Trying to get value out of text view in list view click event in android

前端 未结 1 1010
终归单人心
终归单人心 2020-12-18 11:45

I have a click event hooked up to my listview as shown.

int[] GenusListIDs = { R.id.txt_ID, R.id.txt_Genus, R.id.txt_Count };
        SimpleCursorAdapter ada         


        
相关标签:
1条回答
  • 2020-12-18 12:27

    This should do it.

    TextView tv = (TextView)view.findViewById(R.id.txt_Genius);
    String genus = tv.getText().toString();
    

    Then put it into the intent extras, I think you already know this bit.

    i.putExtra("genius", genius);
    

    Edit;

    In your new activity you would access the intent and get the extras bundle. You can then access anything you placed in the intent on your previous activity like below;

    Bundle extras = getIntent().getExtras();
    String genius = extras.getString("genius");
    // pop some toast to show the value of genius - not required but shows it works :) 
    Toast.makeText(this, "Genius value: " + genius, Toast.LENGTH_SHORT).show();
    
    0 讨论(0)
提交回复
热议问题