开发者

Android more complex ListView tutorial [closed]

Closed. This question is seeking recommendations for books, tools, software libraries, and more. It does not meet Stack Overflow guidelines guidelines. It is not currently accepting answers.

We don’t allow questions seeking recommendations for boo开发者_如何学Goks, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.

Closed 7 years ago.

Improve this question

I've just started out coding for Android but am struggling to get my head around listviews.

For example I need to understand how I can show another listview when clicking on an item in the first listview. Also how I can display a textview when clicking on an item in a listview.

If anyone knows of any good tutorials or examples please let me know.

Thanks a lot


Here are some links for you are looking for. Advanced but if you stick with it and dont give up on this, you will learn a ton!!! Take a look:

Android: ListView elements with multiple clickable buttons

Android custom list item with nested widgets


For example I need to understand how I can show another listview when clicking on an item in >the first listview. Also how I can display a textview when clicking on an item in a listview.

In android and java too, you can use listener to listen event. In your case you want know when a user click on an item, so you'll need a onclicklistener which will call an another activity with another listview. For the textview when clicking I think you want speak of Toast, it's a kind of notification at the bottom of screen.

a link with good examples : http://developer.android.com/guide/topics/ui/ui-events.html


Thanks for all the links everyone, Extremely useful!

I have solved what I needed to do, it might be extremely crude and inefficient but it works until I learn more at least.

This allows me to link together several different view types.

package com.android.AndroidViews;

import android.app.ListActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ArrayAdapter;

public class AndroidViews extends ListActivity {
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setListAdapter(ArrayAdapter.createFromResource(getApplicationContext(),
                R.array.list_titles, R.layout.list_item));

        getListView().setOnItemClickListener(new OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view,
                      int position, long id) {
                    switch( position )
                    {
                       case 0:  Intent newActivity = new Intent(AndroidViews.this,LinearView.class);
                                startActivity(newActivity);
                                break;
                       case 1:  Intent newActivity1 = new Intent(AndroidViews.this,List2.class);
                                startActivity(newActivity1);
                                break;
                    }
                }
        });
    }
}


I don't know of any good tutorial but for the first question you ask :

"I need to understand how I can show another listview when clicking on an item in the first listview."

I assume you want to keep the same list view in the same activity. So just change the adapter of the list view. If it's cursor based, don't forget to manage your cursor. Once you switched to the new adapter, call the

notifyDatasetChanged() 

method of you adapter to refresh the view.

Regarding the second question "Also how I can display a textview when clicking on an item in a listview.", it's too fuzzy for me. What do you wanna do ? Edit a list item directly in place, popup a dialog with an edit text ?

Regards, Stéphane

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜