This is my application , I have 3 layout
... help me................... "
I have 10 button
in my first layout
that the text of these button are 10 title
(title 1 ,..... title 10).... When I press one of them a text that relates to one of titles ( txt1 ,tx2 ........ or txt10 )is shown in second layout .................
imagine .... you press title 1 and then txt1 is shown and when you read , this txt is your interest ......... The main question is : I want to have another layout (3rd) with listview that when you are interested in for example txt1 from second layout, you press a button and the first item of listview will make and it's text is title 1 ... and when you run my app after a while you go to your interests and read txt1 that you had choosed it before ......
what can I do ????
You simply create a public static ArrayList in your third Acitivity of your 3rd layout, where your list view exist. When you click a button in 2nd layout access the static arraylist of 3rd layout and add the text to it.
In 3rd Activity than create a ArrayAdapter object that use your static Arraylist. Use this Adapter with you ListView. Here is sample code
In 3rd Activity where you use your 3rd layout
Public static ArrayList<String> listData = new ArrayList<String>();
ArrayAdapter<String> adaper;
ListView lv = (ListView) findViewbyId(R.id.you_list_view_id);
if(listData.size > 0)
{
adaper = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, android.R.id.text1, listData);
lv.setAdapter(adapter);
}
In 2nd layout's activity you add item to data list, when button clicked,
listData.add(text1);
This is sample code i didn't test. if you got any error let me know.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.