this page can run but i want call public class MyCustomAdapter extends
BaseAdapter

for  show data from layout item
How can i do?

2011/8/31, RobinDroid <librain.ro...@gmail.com>:
> Where is the problem?
>
> On Aug 31, 2:09 pm, Jhew SAN <tawisak.ruksu...@gmail.com> wrote:
>> package com.cityweather;
>>
>> import java.io.FileInputStream;
>> import java.io.FileOutputStream;
>> import java.io.IOException;
>> import java.io.InputStreamReader;
>> import java.io.OutputStreamWriter;
>> import java.net.MalformedURLException;
>> import java.net.URL;
>> import java.util.ArrayList;
>>
>> import javax.xml.parsers.ParserConfigurationException;
>> import javax.xml.parsers.SAXParser;
>> import javax.xml.parsers.SAXParserFactory;
>>
>> import org.xml.sax.InputSource;
>> import org.xml.sax.SAXException;
>> import org.xml.sax.XMLReader;
>>
>> import com.cityweather.OZWFGoogleWeatherAPIData;
>> import com.cityweather.OZWFXMLHandler;
>>
>> import android.app.Activity;
>> import android.app.AlertDialog;
>> import android.app.ListActivity;
>> import android.content.Context;
>> import android.content.DialogInterface;
>> import android.content.Intent;
>> import android.os.Bundle;
>> import android.util.Log;
>> import android.view.LayoutInflater;
>> import android.view.View;
>> import android.view.View.OnClickListener;
>> import android.view.ViewGroup;
>> import android.widget.ArrayAdapter;
>> import android.widget.AutoCompleteTextView;
>> import android.widget.BaseAdapter;
>> import android.widget.Button;
>> import android.widget.EditText;
>> import android.widget.ListView;
>> import android.widget.TextView;
>> import android.widget.Toast;
>>
>> public class MyLocationActivity extends ListActivity implements
>> OnClickListener {
>>
>> TextView selection;
>> EditText et;
>> AutoCompleteTextView at;
>> String data[]={};
>>
>> public static int state = 0;
>> public static String city = "";
>> static final String[] COUNTRIES = new String[] {
>>
>> "Harare","Lusaka","Kampala","Tunis","Mbabane","Paramaribo","Khartoum","Pret
>> oria","Mogadishu","Freetown","Victoria","Dakar","Kigali","Abuja","Niamey","
>> Wimdhoek","Maputo","Rabat","Port
>> Louis","Bamako","Lilongwe","Antananarivo","Tripoli","Monrovia","Maseru","Ta
>> rawa","Nairobi","Bissau","Conakry","Accra","Banjul","Libreville","Asmara","
>> Malabo","Cairo","Djibouti","Brazzaville","Moroni","Bangul","Praia","Yaounde
>> ","Bujumbura","Ouagadougou","Garborone","Porto-Novo","Algiers","Hanoi","Tas
>> hkent","Ashkhabad","Bangkok","Dushanbe","Taipei","Colombo","Singapore","Man
>> ila","Islamabad","Kathmandu","Yangon","Ulaanbaatar","Male","Kuala
>> Lumpur","Vientiane","Bishkek","Seoul","Pyongyang","Astana","Tokyo","Jakarta
>> ","New
>> Delhi","Beijing","Phnom Penh","Manama","Baku","Yerevan","Kabul","Kamphaeng
>> Phet","Chiang Rai","Chiang Mai","Tak","Nan"
>> ,"Phichit","Phitsanulok","Phetchabun","Phrae","Mae Hong
>> Son","Lampang","Sukhothai","Uttaradit"
>> ,"Phayao","Chanthaburi","Chon Buri","Chai Nat","Trat","Nakhon
>> Nayok","Nakhon
>> Pathom","Nonthaburi"
>> ,"Pathum Thani","Prachuap Khiri Khan","Prachin
>> Buri","Phetchaburi","Rayong","Ratchaburi","Lop Buri"
>> ,"Samut Prakan","Samut Songkhram","Samut Sakhon","Saraburi","Sing
>> Buri","Suphan Buri"
>> ,"Ang Thong","Sa Kaeo","Kalasin","Chaiyaphum","Yasothon","Maha
>> Sarakham","Loei","Si Sa Ket"
>> ,"Nong Khai","Udon Thani","Ubon Ratchathani","Mukdahan","Amnat
>> Charoen","Nong Bua Lam Phu"
>> ,"Krabi","Trang","Nakhon Si
>> Thammarat","Narathiwat","Pattani","Phuket","Phatthalung"
>> ,"Yala","Songkhla","Satun","Surat Thani"
>> ,""};
>>
>> public void onCreate(Bundle icicle) {
>>
>> super.onCreate(icicle);
>> //WriteSettings(this, "Skopje");
>>
>> data = ReadSettings(this).trim().split(",");
>>
>> data[data.length-1]=data[data.length-1].trim();
>> //Log.v("datodeka", data[30].toString());
>> setContentView(R.layout.lview);
>> setListAdapter(new ArrayAdapter<String>(this,
>> android.R.layout.simple_list_item_1, data));
>> selection = (TextView) findViewById(R.id.selection);
>> //selection.setText(ReadSettings(this));
>> // button
>> // Button del = (Button)findViewById(R.id.btDel);
>> // del.setOnClickListener(new View.OnClickListener() {
>> //
>> // @Override
>> // public void onClick(View v) {
>> // // TODO Auto-generated method stub
>> // Intent intent = new Intent(MyLocationActivity.this,PEdit.class);
>> // startActivity(intent);
>> // }
>> // });
>>
>> Button btnAdd = (Button) findViewById(R.id.btnAdd);
>> btnAdd.setOnClickListener(this);
>>
>> }
>>
>> public class MyCustomAdapter extends BaseAdapter
>> {
>> private ArrayList<String> mData = new ArrayList<String>();
>> private LayoutInflater mInflater;
>> public MyCustomAdapter(Activity context,String c)
>> {
>> mInflater =
>> (LayoutInflater)getSystemService(Context.LAYOUT_INFLATER_SERVICE);
>>
>> }
>>
>> public void addItem(final String item)
>> {
>> mData.add(item);
>> notifyDataSetChanged();}
>>
>> @Override
>> public int getCount() {
>> // TODO Auto-generated method stub
>> return mData.size();
>>
>> }
>>
>> @Override
>> public Object getItem(int position) {
>> // TODO Auto-generated method stub
>> return mData.get(position);
>>
>> }
>>
>> @Override
>> public long getItemId(int position) {
>> // TODO Auto-generated method stub
>> return position;
>>
>> }
>>
>> @Override
>> public View getView(int position, View convertView, ViewGroup parent) {
>> // TODO Auto-generated method stub
>> ViewHolder holder = null;
>> if (convertView == null) {
>> convertView = mInflater.inflate(R.layout.item, null);
>> holder = new ViewHolder();
>> holder.textView = (TextView)convertView.findViewById(R.id.text);
>> convertView.setTag(holder);} else {
>>
>> holder = (ViewHolder)convertView.getTag();}
>>
>> holder.textView.setText(mData.get(position));
>> Log.i("test","test"+ mData);
>> return convertView;
>>
>> }
>> }
>>
>> public static class ViewHolder {
>> public TextView textView;
>>
>> }
>>
>> public void onListItemClick(ListView parent, View v, int position, long
>> id)
>> {
>> //selection.setText(data[position]);
>> MyLocationActivity.state=1;
>> Log.v("mylocation",Integer.toString( state));
>> city=data[position];
>> // AndroidWeatherTab.updateWeather(data[position]);
>>
>> }
>>
>> @Override
>> protected void onResume() {
>> // TODO Auto-generated method stub
>> super.onResume();
>> // AndroidWeatherTab.switchTab("now");
>> setListAdapter(new ArrayAdapter<String>(this,
>> android.R.layout.simple_list_item_1, data));
>>
>> }
>>
>> public void WriteSettings(Context context, String data) {
>> FileOutputStream fOut = null;
>> OutputStreamWriter osw = null;
>> try {
>> fOut = openFileOutput("loc1.txt", MODE_APPEND);
>> osw = new OutputStreamWriter(fOut);
>> osw.write( data+",");
>> osw.flush();
>> Toast.makeText(context, "Settings saved", Toast.LENGTH_LONG)
>> .show();
>>
>> }
>>
>> catch (Exception e) {
>>
>> e.printStackTrace();
>>
>> Toast.makeText(context, "Settings not saved", Toast.LENGTH_LONG)
>> .show();
>>
>> }
>>
>> finally {
>>
>> try {
>>
>> osw.close();
>> fOut.close();
>>
>> } catch (IOException e) {
>>
>> e.printStackTrace();
>>
>> }
>> }
>> }
>>
>> // Read settings
>> public String ReadSettings(Context context) {
>> FileInputStream fIn = null;
>> InputStreamReader isr = null;
>>
>> char[] inputBuffer = new char[255];
>> String data = null;
>> try {
>>
>> fIn = openFileInput("loc1.txt");
>> if(fIn==null)
>> {
>> return " ,";}
>>
>> isr = new InputStreamReader(fIn);
>> isr.read(inputBuffer);
>> data = new String(inputBuffer);
>> Toast.makeText(context, "Settings read", Toast.LENGTH_SHORT).show();
>>
>> }
>>
>> catch (Exception e) {
>> e.printStackTrace();
>> Toast.makeText(context, "Settings not read", Toast.LENGTH_SHORT)
>> .show();} finally {
>>
>> try {
>> if(fIn==null)
>> {
>> return "";}
>>
>> isr.close();
>> fIn.close();} catch (IOException e) {
>>
>> e.printStackTrace();
>>
>> }
>> }
>> return data;
>> }
>>
>> @Override
>> public void onClick(View v) {
>> // TODO Auto-generated method stub
>> at = (AutoCompleteTextView)findViewById(R.id.autoCompleteTextView1);
>> ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
>> R.layout.list_item, COUNTRIES);
>> at.setAdapter(adapter);
>> // et = (EditText)findViewById(R.id.et1);
>>
>> URL url;
>> try {
>> /* Get what user typed to the EditText. */
>>
>> String town = at.getText().toString();
>>
>> String queryString = "http://www.google.com/ig/api?weather=";
>> + town;
>> /* Replace blanks with HTML-Equivalent. */
>> url = new URL(queryString.replace(" ", "%20"));
>>
>> /* Get a SAXParser from the SAXPArserFactory. */
>> SAXParserFactory spf = SAXParserFactory.newInstance();
>> SAXParser sp = spf.newSAXParser();
>>
>> //get the XMLReader of the SAXParser
>> XMLReader xr = sp.getXMLReader();
>> OZWFXMLHandler xmlHandler = new OZWFXMLHandler();
>> xr.setContentHandler(xmlHandler);
>>
>> //parse the xml-data from URL
>> xr.parse(new InputSource(url.openStream()));
>>
>> //show data
>> OZWFGoogleWeatherAPIData aa = xmlHandler.getData();
>>
>> {
>> // et = (EditText)findViewById(R.id.et1);
>> // String cityParamString = et.getText().toString();
>> WriteSettings(MyLocationActivity.this, aa.getCity()+"
>> "+aa.getCurrentConditionData().getTemp_c());
>> data = ReadSettings(MyLocationActivity.this).split(",");
>> data[data.length-1]=data[data.length-1].trim();
>> onResume();}
>> }catch (MalformedURLException e) {
>>
>> // TODO Auto-generated catch block
>> e.printStackTrace();} catch (ParserConfigurationException e) {
>>
>> // TODO Auto-generated catch block
>> e.printStackTrace();} catch (SAXException e) {
>>
>> // TODO Auto-generated catch block
>> e.printStackTrace();} catch (IOException e) {
>>
>> // TODO Auto-generated catch block
>> e.printStackTrace();
>>
>>
>>
>>
>>
>>
>>
>> }
>> }
>> }
>
> --
> You received this message because you are subscribed to the Google
> Groups "Android Developers" group.
> To post to this group, send email to android-developers@googlegroups.com
> To unsubscribe from this group, send email to
> android-developers+unsubscr...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/android-developers?hl=en

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to