Storing in ArrayList then sending via intent to be stored in ListView

+1 Muhammad Faisal Hyder · August 17, 2014
Hi , to all , thank god i found this  forum , after posting on Stackoverflow and for asking help on diff. sites none helped...!

Task: When i click button it saves in Array-List (coz I have to populate a list in receiving Activity , but not open 2nd activity yet.) then send to another activity receives in Array-List then set this coming Array-List in a ListView.
Finally when i click the "History" button it opens activity and show me the list..!
thanks in advance , really need help in this.!

Sending Code from class Main:-


case R.id.equal:
if (TextUtils.isEmpty(etDisp.getText().toString())) {
                return;
            }

            ArrayList<String> sendinglist = new ArrayList<String>();
           String storage = etDisp.getText().toString();
            sendinglist.add(storage.toString());

           
            Intent i = new Intent(Main.this, History.class);
            i.putStringArrayListExtra("value", (ArrayList<String>) sendinglist);
            // startActivity(i); because i want to start activity on click of another button.!
            break;

        }







Receiving Code in class History:-



public class History extends Activity implements View.OnClickListener {

Button Back;
ListView lv;

public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.history);

Back = (Button) findViewById(R.id.back);
lv = (ListView) findViewById(R.id.list);
Back.setOnClickListener(this);
Bundle b = getIntent().getExtras();
if (b != null) {
ArrayList<String> receivinglist = (ArrayList<String>) b.getStringArrayList("value");
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
android.R.layout.simple_expandable_list_item_1,receivinglist);
lv.setAdapter(adapter);
adapter.notifyDataSetChanged();
}
} else {
Toast.makeText(this, "NO data Found", Toast.LENGTH_SHORT).show();
}






Post a Reply

Replies

Oldest  Newest  Rating
0 Muhammad Faisal Hyder · August 19, 2014
I have finally solved this Problem.! If any one needs help relating this topic kindly leave a message.
0 Muhammad Faisal Hyder · August 17, 2014
Anybody plz....?
0 Muhammad Faisal Hyder · August 17, 2014
NO one here...........? any one who knows this ....!
0 Çağlan Turgut · August 17, 2014
The community in Bucky's Room is not so big so you will have to wait till someone who knows the answer sees the topic.Sorry,  I suggest you to wait until tomorrow. I don't really know much about the topic so I can't help :(.But I'm sure someone will if you wait long enough.
0 Mathias Frits Rørvik · August 17, 2014
Put your code these boxes
System.out.println("Nobody will bother to read your code otherwise");
0 Muhammad Faisal Hyder · August 17, 2014
I have achieved it half way...!
I click Equals-to and it stores in Shared Preferences and when i click History button it simply opens activity with my Calculation.! Hurray...! but........ :(  i need ARRAY to save my inputs which Shared Preferences support but with complexity.! now conquering this thing......! 
0 Mathias Frits Rørvik · August 17, 2014
Now you've got to indent the code, so people can read

Example:
Like this
if (condition) {
System.out.println(243);
}


and not like this:
if (condition) {
System.out.println(243);
}
  • 1

Java / Android Development

107,304 followers
About

Very popular language used to create desktop applications, website applets, and Android apps.

Links
Moderators
Bucky Roberts Administrator