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
    }

2 Answers 2

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.

Sign up to request clarification or add additional context in comments.

10 Comments

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?
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.
ok ,i went through it,i even found the complete example at the end,but in that how to implement onClick event
You found? I gave you a link for complete example. 'listView.setOnItemClickListener' in order to assighn on item click listener.
i am following has you said stackoverflow.com/questions/8166497/… last post from Louis,stil working on
|
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

6 Comments

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?
In that case iterate over your list get all messages store in in an array and pass that to the Adapters constructor.
u mean store in string[]
Yes if that's what getMessage() returns.
it wil return me a string
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.