[android-developers] i have problem about listview adding can any one help me?
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","Pretoria","Mogadishu","Freetown","Victoria","Dakar","Kigali","Abuja","Niamey","Wimdhoek","Maputo","Rabat","Port Louis","Bamako","Lilongwe","Antananarivo","Tripoli","Monrovia","Maseru","Tarawa","Nairobi","Bissau","Conakry","Accra","Banjul","Libreville","Asmara","Malabo","Cairo","Djibouti","Brazzaville","Moroni","Bangul","Praia","Yaounde","Bujumbura","Ouagadougou","Garborone","Porto-Novo","Algiers","Hanoi","Tashkent","Ashkhabad","Bangkok","Dushanbe","Taipei","Colombo","Singapore","Manila","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(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 mData = new ArrayList(); 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)
[android-developers] I implement for delete row from listview but have force close
Logcat say error this line viewInfo.removeViewAt(positionToRemove); final ListView viewInfo = (ListView)findViewById(R.id.listView1); final SWFForeCastInfoLayoutAdapter adapter = new SWFForeCastInfoLayoutAdapter(this, data, data.getCurrentConditionData()); viewInfo.setAdapter(adapter); adapter.notifyDataSetChanged(); viewInfo.setOnItemClickListener(new OnItemClickListener() { @Override public void onItemClick(AdapterView a, View v, final int position, long id) { AlertDialog.Builder adb=new AlertDialog.Builder(SearchActivity.this); adb.setTitle("Delete?"); adb.setMessage("Are you sure you want to delete " + position); final int positionToRemove = position; adb.setNegativeButton("Cancel", null); adb.setPositiveButton("Ok", new AlertDialog.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { // TODO Auto-generated method stub viewInfo.removeViewAt(positionToRemove); adapter.notifyDataSetChanged(); }}); adb.show(); } }); any body help? best regard; -- 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
[android-developers] Re: I implement for delete row from listview but have force close
change from viewInfo.removeViewAt(positionToRemove); to what -- 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
[android-developers] Re: I implement for delete row from listview but have force close
i will send my full source to ur mail what is ur mail -- 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
[android-developers] Re: I implement for delete row from listview but have force close
i don't know. plz tell me -- 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
[android-developers] Re: I implement for delete row from listview but have force close
adap.remove(); don't have have only adapter.registerDataSetObserver(); -- 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
[android-developers] Re: I implement for delete row from listview but have force close
how can i change that line? -- 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
[android-developers] MODE_APPEND can not use
@Override public View getView(int position, View convertView, ViewGroup parent) { // TODO Auto-generated method stub if(convertView==null){ if(convertView==null){ convertView = (LinearLayout)layoutInflater.inflate(R.layout.searchlayout, null); TextView tx1 = (TextView)convertView.findViewById(R.id.ccd_textView1); tx1.setText(data.getCity()); TextView tx2 = (TextView)convertView.findViewById(R.id.ccd_textViewDetail_1); tx2.setText(ccd.getTemp_c()); WriteSettings(SWFForeCastInfoLayoutAdapter.this, data.getCity()+" "+ccd.getTemp_c()); ImageView im = (ImageView)convertView.findViewById(R.id.imageView1); im.setImageResource(R.drawable.delete); } } return convertView; } private void WriteSettings( SWFForeCastInfoLayoutAdapter swfForeCastInfoLayoutAdapter, String data) { // TODO Auto-generated method stub FileOutputStream fOut = null; OutputStreamWriter osw = null; try { fOut = openFileOutput("loc1.txt", MODE_APPEND); osw = new OutputStreamWriter(fOut); osw.write( data+","); osw.flush(); // Toast.makeText(swfForeCastInfoLayoutAdapter, "Settings saved", Toast.LENGTH_LONG) // .show(); }catch(Exception e) { e.printStackTrace(); // Toast.makeText(swfForeCastInfoLayoutAdapter, "Settings not saved", Toast.LENGTH_LONG) // .show(); } finally { try { osw.close(); fOut.close(); } catch (IOException e) { 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
[android-developers] i do weather forecast and have problem about add city
i can only add city one line now i get data from google how can i save data and add city delete city e mail tawisak.ruksu...@gmail.com -- 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
[android-developers] how to loop XmlSerializer
This is for 1 time File newxmlfile = new File("/sdcard/new.xml"); try{ newxmlfile.createNewFile(); }catch(IOException e){ Log.e("IOException", "exception in createNewFile() method"); } FileOutputStream fileos = null; try{ fileos = new FileOutputStream(newxmlfile); }catch(FileNotFoundException e){ Log.e("FileNotFoundException", "can't create FileOutputStream"); } XmlSerializer serializer = Xml.newSerializer(); try { serializer.setOutput(fileos, "UTF-8"); serializer.startDocument(null, Boolean.valueOf(true)); serializer.setFeature("http://xmlpull.org/v1/doc/features.html#indent-output";, true); serializer.startTag(null, "root"); serializer.startTag(null, "city"); serializer.startTag(null, data.getCity()); serializer.endTag(null, data.getCity()); serializer.endTag(null, "city"); serializer.startTag(null, "temperature"); serializer.attribute(null, "temperature", data.getCurrentConditionData().getTemp_c()); serializer.endTag(null, "temperature"); serializer.endTag(null, "root"); serializer.endDocument(); serializer.flush(); fileos.close(); }catch(Exception e) { Log.e("Exception","error occurred while creating xml file"); } -- 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
[android-developers] how to make iteration XmlSerializer for store data
File newxmlfile = new File("/sdcard/sss.xml"); try{ newxmlfile.createNewFile(); }catch(IOException e){ Log.e("IOException", "exception in createNewFile() method"); } FileOutputStream fileos = null; try{ fileos = new FileOutputStream(newxmlfile); }catch(FileNotFoundException e){ Log.e("FileNotFoundException", "can't create FileOutputStream"); } XmlSerializer serializer = Xml.newSerializer(); try { serializer.setOutput(fileos, "UTF-8"); serializer.startDocument(null, Boolean.valueOf(true)); serializer.setFeature("http://xmlpull.org/v1/doc/features.html#indent-output";, true); serializer.startTag(null, "root"); serializer.startTag(null, "data"); serializer.startTag(null, "city"); serializer.startTag(null, data.getCity()); serializer.endTag(null, data.getCity()); serializer.endTag(null, "city"); serializer.startTag(null, "temperature"); serializer.attribute(null, "temperature", data.getCurrentConditionData().getTemp_c()); serializer.endTag(null, "temperature"); serializer.endTag(null, "data"); serializer.endTag(null, "root"); serializer.endDocument(); serializer.flush(); fileos.close(); }catch(Exception e) { Log.e("Exception","error occurred while creating xml file"); } -- 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
[android-developers] How can i remove item in listview
listViewInfo = (ListView)findViewById(R.id.listView1); tempListAdapter = new SimpleAdapter(this, weatherlist, R.layout.list_row, new String[] {"city", "low", "high"}, new int[] {R.id.CITY_CELL, R.id.LOW_CELL, R.id.HIGH_CELL}); listViewInfo.setAdapter(tempListAdapter); tempUpdate(); listViewInfo.setOnItemClickListener(new OnItemClickListener() { @Override public void onItemClick(AdapterView a, View v, final int position, long id) { // TODO Auto-generated method stub AlertDialog.Builder adb = new AlertDialog.Builder( EditCity.this); adb.setTitle("Delete?"); adb.setMessage("Are you sure you want to delete "); // final int positionToRemove = position; adb.setNegativeButton("Cancel", null); adb.setPositiveButton("Ok", new AlertDialog.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { // TODO Auto-generated method stub try { weatherlist.remove(map); listViewInfo.setAdapter(tempListAdapter); }catch(Exception e) { // } } }); adb.show(); } }); } } This can remove only 1 row -- 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
[android-developers] How to delete tag in XmlSerializer when i remove from listview
package demo.weatherforecast.main; import java.io.File; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; import java.util.ArrayList; import java.util.HashMap; import java.util.Iterator; import org.xmlpull.v1.XmlSerializer; import android.app.Activity; import android.app.AlertDialog; import android.content.DialogInterface; import android.os.Bundle; import android.util.Log; import android.util.Xml; import android.view.View; import android.widget.AdapterView; import android.widget.AdapterView.OnItemClickListener; import android.widget.ListView; import android.widget.SimpleAdapter; import android.widget.Toast; public class EditCity extends Activity { String xmlFilepath = "/sdcard/searchcity.xml"; ArrayList allListCity = new ArrayList(); SimpleAdapter tempListAdapter; ArrayList> weatherlist = new ArrayList>(); HashMap map = new HashMap(); ListView listViewInfo; public void tempUpdate(){ XmlHelper xmlHp = new XmlHelper(); if(xmlHp.readAllCity().isEmpty()){ } else{ ArrayList tmpweatherArr = new ArrayList(); WeatherHelper whp = new WeatherHelper(); tmpweatherArr = xmlHp.readAllCity(); Iterator itr = tmpweatherArr.iterator(); String[] tmpResult = new String[3]; while(itr.hasNext()){ tmpResult = whp.getCurrentTemp(itr.next().toString()); if(tmpResult[0].equalsIgnoreCase("error")){ Toast.makeText(this, "Cannot retieve weather infomation from WebService", Toast.LENGTH_LONG).show(); } else{ Toast.makeText(this, "City "+ tmpResult[0] +" Lowest:"+ tmpResult[1] +" Highest:"+ tmpResult[2], Toast.LENGTH_LONG).show(); map = new HashMap(); map.put("city", tmpResult[0]); map.put("low", tmpResult[1]); map.put("high", tmpResult[2]); weatherlist.add(map); //weatherArr.add(tmpResult[0]); listViewInfo.setAdapter(tempListAdapter); } } } } /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.edit); listViewInfo = (ListView)findViewById(R.id.listView1); tempListAdapter = new SimpleAdapter(this, weatherlist, R.layout.list_row, new String[] {"city", "low", "high"}, new int[] {R.id.CITY_CELL, R.id.LOW_CELL, R.id.HIGH_CELL}); listViewInfo.setAdapter(tempListAdapter); tempUpdate(); listViewInfo.setOnItemClickListener(new OnItemClickListener() { @Override public void onItemClick(AdapterView a, View v, final int position, long id) { // TODO Auto-generated method stub AlertDialog.Builder adb = new AlertDialog.Builder( EditCity.this); adb.setTitle("Delete?"); adb.setMessage("Are you sure you want to delete "); // final int positionToRemove = position; adb.setNegativeButton("Cancel", null); adb.setPositiveButton("Ok", new AlertDialog.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { // TODO Auto-generated method stub try { weatherlist.remove(position); listViewInfo.setAdapter(tempListAdapter); System.out.println(position); WriteIntoXML(weatherlist); }catch(Exception e) { // } } private void WriteIntoXML(ArrayList> weatherlist) { // TODO Auto-generated method stub System.out.println(weatherlist); File newxmlfile = new File(xmlFilepath); try{ newxmlfile.createNewFile(); }catch(IOException e){ Log.e("IOException", "exception in createNewFile() method"); } FileOutputStream fileos = null; try{ fileos = new FileOutputStream(newxmlfile); }catch(FileNotFoundException e){ Log.e("FileNotFoundException", "can't create FileOutputStream"); } try{ fileos = new FileOutputStream(newxmlfile); }catch(FileNotFoundException e){ Log.e("FileNotFoundException", "can't create FileOutputStream"); } XmlSerializer serializer = Xml.newSerializer(); //allListCity.contains(weatherlist); try { Iterator itr = allListCity.iterator(); serializer.setOutput(fileos, "UTF-8"); serializer.startDocument(null, Boolean.valueOf(true)); serializer.setFeature("http://xmlpull.org/v1/doc/features.html#indent-output";, true); serializer.startTag(null, "root"); while(itr.hasNext()){ serializer.startTag(null, "city"); serializer.startTag(null, "cityname"); serializer.text(itr.next().toString()); serializer.endTag(null, "cityname"); serializer.startTag(null, "low"); serializer.text("0"); serializer.endTag(null, "low"); serializer.startTag(null, "high"); //serializer.attribute(null, "user", user_arr[i]); serializer.text("0"); serializer.endTag(null, "high"); serializer.endTag(null, "city"); } serializer.endTag(null, "root"); serializer.endDocument(); serializer.flush(); fileos.close(); }catch(Exception e){ Log.e("Exception","error occurred while creating xml file"); } } }); adb.show(); } }); } } Problem --->When i delete item in listview , How can i remove that tag in XmlSerializer in SD card ? -- You receiv
[android-developers] how can i get data value from ArrayList> weatherlist to string
listViewInfo.setOnItemClickListener(new OnItemClickListener() { @Override public void onItemClick(AdapterView a, View v, final int position, long id) { // TODO Auto-generated method stub AlertDialog.Builder adb = new AlertDialog.Builder( EditCity.this); adb.setTitle("Delete?"); adb.setMessage("Are you sure you want to delete "); // final int positionToRemove = position; adb.setNegativeButton("Cancel", null); adb.setPositiveButton("Ok", new AlertDialog.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { // TODO Auto-generated method stub try { weatherlist.remove(position); listViewInfo.setAdapter(tempListAdapter); System.out.println(position); WriteIntoXML(weatherlist); }catch(Exception e) { // } } private void WriteIntoXML(ArrayList> weatherlist) { // TODO Auto-generated method stub System.out.println(weatherlist); // addListCity(); } }); adb.show(); } }); } } -- 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
[android-developers] Re: how can i get data value from ArrayList> weatherlist to string
I want to get value from weatherlist to write in XML -- 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