1

How can I get all textviews values and pass it through intent to another activity at once? Here is my source code:

class ViewHolder extends RecyclerView.ViewHolder {

    public ImageView imgThumbnail;
    public TextView tvspecies;
    public View view;
    public ViewHolder(View itemView) {
        super(itemView);
        view = itemView;
        imgThumbnail = (ImageView) view.findViewById(R.id.img_thumbnail);
        tvspecies = (TextView) view.findViewById(R.id.tv_species);
        ArrayList<TextView> list = new ArrayList<TextView>();

        view.setOnClickListener(new View.OnClickListener(){

            @Override
            public void onClick(View v) {


                String intentSt = ((TextView) view.findViewById(R.id.tv_species)).getText().toString();

            }
        });
    }
}
prompteus
  • 1,051
  • 11
  • 26
Harish Kumar
  • 101
  • 1
  • 1
  • 6

2 Answers2

0

For passing value check this question: How do I pass data between Activities in Android application?

Also you can change

String intentSt = ((TextView) view.findViewById(R.id.tv_species)).getText().toString();

To

String intentSt = tvspecies.getText().toString();
Community
  • 1
  • 1
Benbeta
  • 19
  • 5
  • thanks to your response, i tried but using this we will get only the current textview value in string. but its really helpful – Harish Kumar Nov 01 '15 at 06:13
0

I am not sure what exactly you are trying to do (maybe you don't need to send the values using intent), but you can do it using putExtra for string array:

Intent intent = new Intent(some_action);
intent.putExtra(key, String[] values);

If you need to keep reference to each textview you can use the regualrd putExtra(key, String) where the key is the tag you added to your textview or stringify its id.

If you want to get the values dynamically you can use this:

Intent intent = new Intent();
for (int i = 1; i < NUM_OF_TEXT_VIEWS; i++){
   String key = "txtView_" + i;
   int iterTxtViewId = getResources().getIdentifier(key, "id", getPackageName());
   TextView iterTxtView = (TextView)findViewById(iterTxtViewId);
   String value = iterTxtView.getText();

   intent.putExtra(key, value);
   //or
   //String anotherKey = (String)iterTxtView.getTag();
   //intent.putExtra(anotherKey, value);
}
MikeL
  • 5,385
  • 42
  • 41
  • Thanks for your response michael but i getting values dynamically in textview, so i need to get all textview values in array and send the values to another intent – Harish Kumar Nov 01 '15 at 06:11
  • So you can use the second method i proposed. – MikeL Nov 01 '15 at 09:52
  • I added a code for dynamic collection of values from TextView (or EditText) – MikeL Nov 01 '15 at 10:02
  • I am new to android so please can u able elaborate the second method which u proposed – Harish Kumar Nov 01 '15 at 16:26
  • The key can be the id of the textview (in the above example all textviews have a prefix of "textView_" or you can use a predefine tag that is set to the view (you can set the tag programatically or within your xml layout file for each textview). – MikeL Nov 01 '15 at 21:42
  • how can i get the count of text view (i.e) NUM_OF_TEXT_VIEWS – Harish Kumar Nov 02 '15 at 07:14
  • This is something that you should know if you build the UI. You can also iterate through views children and look for TextViews but I dont think this is what you want. More over this technic already applies that you put a predefined prefix for the textview id so you have to know the number of textviews. – MikeL Nov 02 '15 at 07:26