i need help here. Lets say that I have a listview taken from database :
-- car
-- refrigerator
-- pencil
-- motorcycle
This is what i want. When i clicked at car or other option, it will change to broken.
-- broken
-- refrigerator
-- pencil
-- motorcycle
I used this before
lv = (ListView) findViewById(R.id.listView);
lv.setOnItemClickListener(new OnItemClickListener()
{
public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,long arg3)
{
TextView mTextView = (TextView) arg1;
mTextView.setText("broken");
//Toast.makeText(getApplicationContext(), data.get(arg2).toString(),3000).show();
}});
the problem is when i use back button and go to that page again, it will be back like before....
Any idea ?????
Here is my full code
package com.test.first;
import java.util.ArrayList;
import android.app.Activity;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;
public class Listview extends Activity
{
SQLiteDatabase mydb;
ListView lv;
ArrayList data;
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_listview);
//=====CODE FOR SHOWING THE DATA IN TOAST =======
lv = (ListView) findViewById(R.id.listView);
lv.setOnItemClickListener(new OnItemClickListener()
{
public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,long arg3)
{
TextView mTextView = (TextView) arg1;
mTextView.setText(data.get(arg2) + " has been bought !");
//Toast.makeText(getApplicationContext(), data.get(arg2).toString(),3000).show();
}});
mydb = Listview.this.openOrCreateDatabase("My", MODE_PRIVATE, null);
mydb.execSQL("CREATE TABLE IF NOT EXISTS list (id INTEGER PRIMARY KEY AUTOINCREMENT,list varchar);");
data = new ArrayList();
//=VIEW BUTTON TO SHOW DATA INSERTED IN THE LISTVIEW=======
Cursor cursor2=mydb.rawQuery("SELECT * FROM LIST;", null);
if (cursor2.moveToFirst())
{
Toast.makeText(getApplicationContext(), "Shop List", 3000).show();
data.clear();
do
{
data.add(cursor2.getString(cursor2.getColumnIndex("list")));
}
while (cursor2.moveToNext());
//====CODE FOR SHOWING DATA AS A SIMPLE LIST ITEM=========================================
ArrayAdapter <String> adapter=new ArrayAdapter<String> (Listview.this,android.R.layout.simple_list_item_1,data);
lv.setAdapter(adapter);
}
else
{
Toast.makeText(getApplicationContext(), "DATA NOT AVAILABLE", 3000).show();
}
cursor2.close();
}
}