In my android app I need to pass the data of listview to another activity,for example If I click the Item "Food" in listview,I want get that "Food" in the textview of another activity.
Here is my code..
public class list extends Activity {
String selected_id = "";
SimpleCursorAdapter adapter;
DBhelper helper;
SQLiteDatabase db;
Button btnd;
String budget;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.listlayout);
helper = new DBhelper(this);
Listview rldlist = (ListView) findViewById(R.id.rldlist);
TextView ed= (TextView) findViewById(R.id.addbud);
rldlist.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> adapter, View v, int position, long id) {
Cursor row = (Cursor) adapter.getItemAtPosition(position);
selected_id = row.getString(0);
budget = row.getString(1);
System.out.print("budget is"+budget);
ed.setText(budget);
}
});
In the above code,TextView ed= (TextView) findViewById(R.id.addbud);
is referring the textview from another activity.
But problem now is,The TextView remains empty.
Below one is the code to go another activity.
rldlist.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> arg0, View arg1, int position, long arg3) {
Intent myIntent = new Intent(list.this, addbudget.class);
list.this.startActivity(myIntent);
}
});