0

I have to display a list of messages and make it clickable ,i have read ListView andtried to use it,but i have data in something like below code,how will i add to adapter? from this list i will loop and get messages say list.get(i).getMessage(); which has to be displayed and there are multiple messages.

@Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);
        setContentView(R.layout.reminderlist);
        getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE,   R.layout.reminderlayout);
        setContentView(R.layout.reminderlayout);
        getWindow().getDecorView().setBackgroundColor(Color.WHITE);
        ArrayList<GetReminder> list = (ArrayList<GetReminder>) getIntent().getSerializableExtra("reminderList");
        System.out.println("size is >>>"+list.size());
        // Binding resources Array to ListAdapter
    }
jenil
  • 141
  • 11

2 Answers2

1

You can do

setListAdapter(new ArrayAdapter<GetReminder>(getApplicationContext(), R.layout.reminderlayout,(GetReminder[]) list.toArray()));

considering this code is in onCreate() method of your class that extends ListActivity

Aniket Thakur
  • 66,731
  • 38
  • 279
  • 289
1

Implement your custom adapter parametrized with GetReminder. Take a look here for example. Than you can do something like this:

ArrayList<GetReminder> list = (ArrayList<GetReminder>) getIntent().getSerializableExtra("reminderList");
ListView listView = findViewById(R.id.listview);
MyCustomAdapter adapter = new MyCustomAdapter(this, 0);
adapter.addAll(list)

or just pass your list as a third parameter in MyCustomAdapter constructor.

Community
  • 1
  • 1
Divers
  • 9,531
  • 7
  • 45
  • 88
  • i am going to get messages from list like...list.get(i).getMessage(); and they are 'n' number of messages to be displayed in list,whether your code will work out? – jenil Mar 22 '15 at 08:44
  • Please, check getView method in example was given by me. Each call of this method represent 1 row in your list. Here you have to write your realisation how to show information from your list in your ListView. – Divers Mar 22 '15 at 08:46
  • ok ,i went through it,i even found the complete example at the end,but in that how to implement onClick event – jenil Mar 22 '15 at 10:04
  • You found? I gave you a link for complete example. 'listView.setOnItemClickListener' in order to assighn on item click listener. – Divers Mar 22 '15 at 11:13
  • i am following has you said http://stackoverflow.com/questions/8166497/custom-adapter-for-list-view last post from Louis,stil working on – jenil Mar 22 '15 at 14:43
  • RuntimeException: Your content must have a ListView whose id attribute is 'android.R.id.list' ....,getting this exception – jenil Mar 22 '15 at 15:25
  • There is one more copy-past from some source without understanding (or even efforts) what are you doing. Can't help in this case. – Divers Mar 22 '15 at 15:42
  • yes i tried this code in a sample app on my side to understand,but after applying to my prj it caused issue...,i am a newbie to this android so i took over. – jenil Mar 22 '15 at 16:22
  • All this our discussion is not related to this question. If you have further question - ask it in separate one. This one is answered (at least I think so) – Divers Mar 22 '15 at 16:54
  • Can you please see this http://stackoverflow.com/questions/29215730/server-not-able-to-read-parameters-while-making-a-webservice-connection – jenil Mar 23 '15 at 16:46