-2

i have a custom listview that fill from database and i want when click on any item value of textview pass to another activity, how should i do? please help me!

this is all code , thanks u source code: Edit:

    public class ListActivity extends Activity {

    String value = "";
    MovieDB myDbHelper;
    SQLiteDatabase db;
    ListAdapter adapter;
    ArrayList<HashMap<String, String>> data;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.list_layout);


        final ListView lst=(ListView) findViewById(R.id.listView1);

        Load_Database();
        db = myDbHelper.getReadableDatabase();


        Cursor  c = db.rawQuery("select * from movie_list where product  = '"+value+"' Or name  like '%"+value+"%'" , null);

            data = new ArrayList<HashMap<String, String>>();

            for (; c.moveToNext();) {
                HashMap<String, String> map = new HashMap<String, String>();
                String img = c.getString(c.getColumnIndex("img"));
                String name = c.getString(c.getColumnIndex("name"));
                map.put("img", img);
                map.put("name", name);
                data.add(map);
            }
            adapter = new ListMovie(this, data);

            lst.setAdapter(adapter);

            lst.setOnItemClickListener(new OnItemClickListener() {

                @Override
                public void onItemClick(AdapterView<?> arg0, View arg1,
                        int arg2, long arg3) {

                     final Intent GoToDisplay = new Intent(ListActivity.this,DisplayActivity.class);

                            GoToDisplay.putExtra("position", data.get(arg2));
                     startActivity(GoToDisplay);


                }

            });


    }


    private void Load_Database() throws Error {
        myDbHelper = new MovieDB(ListActivity.this);
        try {

            myDbHelper.createDataBase();

        } catch (IOException ioe) {

            throw new Error("Unable to create database");

        }

        try {

            myDbHelper.openDataBase();
        } catch (SQLException sqle) {
            throw sqle;
        }
    }
}
Mehdi Rahimi
  • 153
  • 2
  • 13

1 Answers1

0

Step 1:

Just get data from adapter using position in ListView.

For. e.g.

You have ArrayList<String> data;//

then access like,

GoToDisplay.putExtra("position", data.get(arg2)); // as arg2 referees to clicked item position from ListView

Step 2:

Get Clicked TextView from View

TextView clickedTextView = (TextView)arg1.findViewById(// Id of your TextView); // Or get child from view arg1

GoToDisplay.putExtra("position", clickedTextView.getText().toString());

Note: As we don't know your Adapter data, above code is just example for understanding..

user370305
  • 108,599
  • 23
  • 164
  • 151