-3

I want to show all the values which are entered in one list view of another activity and after clicking the button it will be displayed on text view of previous activity in single line

Here is my code for adding to list view:

public class AddAttendees extends Activity{

    AutoCompleteTextView et;
    Button b, Add;
    ListView lv;
    ArrayList<String> al;
    ArrayAdapter<String> aa;
    int position;

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

        Add = (Button) findViewById(R.id.button2);
        et = (AutoCompleteTextView) findViewById(R.id.autoCompleteTextView1);
        b = (Button) findViewById(R.id.button1);
        lv = (ListView) findViewById(R.id.listView1);
        al = new ArrayList<String>();
        aa = new ArrayAdapter<String>(this, 
                android.R.layout.simple_list_item_1, 
                al);
        lv.setAdapter(aa);
        lv.setOnItemClickListener(new OnItemClickListener() {
            @SuppressLint("ShowToast")
            @Override
            public void onItemClick(AdapterView<?> parent, 
                    View v, int arg2,
                    long arg3) {
                String item = al.get(arg2);
                Toast.makeText(getApplicationContext(), item, 0).show();
            }
        });

        b.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {

                String item = et.getText().toString();
                al.add(0, item);

                aa.notifyDataSetChanged();

                et.setText("");
            }
        });

        Add.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v){
                 Intent intent = new Intent(getApplicationContext(), MeetingAgenda.class);

                 String name = al.getText().toString();
                 intent.putExtra("name", name);
                    /* Start LoginSuccess Activity */
                    finish();


            }

        });

    }
}

After click add button the items added to the list view will be displayed in the textview which is at previous activity.

Cᴏʀʏ
  • 105,112
  • 20
  • 162
  • 194

3 Answers3

0

I'm not sure i got the meaning but i think you just need to display values in a single tv's line.

So, you have an activity, call it ActivityWithTextView and the second one (call it ActivityWithListBox

Do the following in ActivityWithListBox

string text = "";
foreach(var listBoxItem in ListBox){
    text += listBoxItem;
    //if you want to add a separator do it here
    //for example 
    text += ", ";
}
//now you got a string with item1, item2, item3, 
//but it end with ", "
//so remove it:
if(text != ""){
    text = text.substring(0, text.length - 3);
    //-3 because 2 is length of ", " 
    //and 1 is for the difference between length and index
    //(length 2 means last index is 1)
}
//now set text:
ActivityWithTextView.TextViewName.setText(text);

and you are done.

I think it should work, i wrote it from here without trying. If you have problems tell me :)

Pier Giorgio Misley
  • 5,305
  • 4
  • 27
  • 66
0
  1. Define the array that populates your adapter in xml. Example.
  2. Use the StringBuilder class to concatenate the array elements into a single String inside a for loop:

    StringBuilder temp = new StringBuilder();
    String[] array = getResources().obtainTypedArray(R.array.*array_id*);
    String tempToString;
    
    for (String element: array) {
        temp.append(element);
        temp.append(", ");
    }
    
    tempToString = temp.toString();
    
  3. Add to your TextView inside onClick(). Example.
Community
  • 1
  • 1
PPartisan
  • 8,173
  • 4
  • 29
  • 48
-2

Use static variables, go through whole array from the list view, add it to the static variable and then display it in textview like

 tv.setText(NameOfYouStaticClass.yourVariable);
Vulovic Vukasin
  • 1,540
  • 2
  • 21
  • 30