在Android的单一活动的多个列表视图? [英] Multiple Listviews in single Activity in Android?

查看:92
本文介绍了在Android的单一活动的多个列表视图?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想有一个活动的多个列表视图。但只有一个 列表视图应在同一时间被显示。的列表视图将被加载 动态。所以,我怎么能填补所有四个列表视图在同一 时间和显示只有一个?

I want to have multiple listviews in single activity. But only one listview should be displayed at one time. The listviews will be loaded dynamically. So, how can I fill all the four listviews at the same time and display only one?

推荐答案

我主要用来显示多个列表视图,你以相同的方式 使用setvisibility建议即。

I have used mostly the same way of showing multiple listviews as you suggested i.e. using setvisibility.

但现在我想要的是拥有所有四个位图图像 列表视图。假设,我的活动开始和数据加载到 所有四个列表视图通过它们结合到各自的适配器。 现在,当我试图使用来获取位图 getDrawingCache()它 一直到我返回null。

But now what I want is to have the Bitmap image of all the four listviews. Suppose, my activity starts and the data are loaded into all four listviews by binding them to their respective adapters. Now, when I am trying to fetch the Bitmap using getDrawingCache() it always returns null to me.

那么,你能不能让我知道我该怎么获取的所有四个位图 列表视图?

So, can you let me know how can I fetch the Bitmap of all the four listviews?

public class HomeScreenActivity extends Activity
{
private ImageView imgBabble = null;
private ListView listBabble = null;
private ListView listVille = null;
private ListView listPrivateMsgs = null;
private ListView listBookmarks = null;
private List<String> tempBabble = null;
private List<String> tempVille = null;
private List<String> tempPrivateMsgs = null;
private List<String> tempBookmarks = null;

//RelativeLayouts
private RelativeLayout babbleLayout = null;
private RelativeLayout villeLayout = null;
private RelativeLayout privateMsgsLayout = null;
private RelativeLayout bookmarksLayout = null;

//Bitmap
private Bitmap babbleShrunkView = null;
private Bitmap villeShrunkView = null;
private Bitmap privateMsgsShrunkView = null;
private Bitmap bookmarksShrunkView = null;

/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) 
{
    super.onCreate(savedInstanceState);
    requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);
    setContentView(R.layout.homescreen);
    getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.customtitle);

    imgBabble = (ImageView) findViewById(R.id.imgBtnBabble);
    Bitmap bitmapOrg = BitmapFactory.decodeResource(getResources(),R.drawable.babble_top_logo);
    BitmapDrawable bmpDrawable = new BitmapDrawable(bitmapOrg);
    imgBabble.setBackgroundDrawable(bmpDrawable);

    //Initialize the layouts for Babble, Ville, Private Messages and Bookmarks
    babbleLayout = (RelativeLayout) findViewById(R.id.babbleLayout);
    babbleLayout.setDrawingCacheEnabled(true);

    villeLayout = (RelativeLayout) findViewById(R.id.villeLayout);
    villeLayout.setDrawingCacheEnabled(true);

    privateMsgsLayout = (RelativeLayout) findViewById(R.id.privatemsgsLayout);
    privateMsgsLayout.setDrawingCacheEnabled(true);

    bookmarksLayout = (RelativeLayout) findViewById(R.id.bookmarksLayout);
    bookmarksLayout.setDrawingCacheEnabled(true);

    //Babble
    tempBabble = new ArrayList<String>();
    tempBabble.add("First Babble");
    tempBabble.add("Second Babble");
    tempBabble.add("Third Babble");

    listBabble = (ListView) findViewById(R.id.listBabble);
    listBabble.setAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_list_item_multiple_choice, tempBabble));
    //babbleShrunkView = babbleLayout.getDrawingCache();

    //babbleLayout = (RelativeLayout) findViewById(R.id.listLayout);

    if(babbleShrunkView == null)
    {
        System.out.println("Babble View is null");
    }

    //Ville
    tempVille = new ArrayList<String>();
    tempVille.add("First Ville");
    tempVille.add("Second Ville");
    tempVille.add("Third Ville");

    listVille = (ListView) findViewById(R.id.listVille);
    //listVille.setDrawingCacheEnabled(true);
    listVille.setAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_list_item_multiple_choice, tempVille));
    //villeShrunkView = villeLayout.getDrawingCache();

    if(villeShrunkView == null)
    {
        System.out.println("Ville View is null");
    }

    //listVille.setVisibility(View.GONE);

    //Private Messages
    tempPrivateMsgs = new ArrayList<String>();
    tempPrivateMsgs.add("First PM");
    tempPrivateMsgs.add("Second PM");
    tempPrivateMsgs.add("Third PM");

    listPrivateMsgs = (ListView) findViewById(R.id.listPrivateMessages);
    //listPrivateMsgs.setDrawingCacheEnabled(true);
    listPrivateMsgs.setAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_list_item_multiple_choice, tempPrivateMsgs));
    //privateMsgsShrunkView = privateMsgsLayout.getDrawingCache();

    if(privateMsgsShrunkView == null)
    {
        System.out.println("Private Messages View is null");
    }

    //listPrivateMsgs.setVisibility(View.GONE);

    //Bookmarks
    tempBookmarks = new ArrayList<String>();
    tempBookmarks.add("First Bookmarks");
    tempBookmarks.add("Second Bookmarks");
    tempBookmarks.add("Third Bookmarks");

    listBookmarks = (ListView) findViewById(R.id.listBookmarks);
    //listBookmarks.setDrawingCacheEnabled(true);
    listBookmarks.setAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_list_item_multiple_choice, tempBookmarks));
    //bookmarksShrunkView = bookmarksLayout.getDrawingCache();

    if(bookmarksShrunkView == null)
    {
        System.out.println("Bookmarks Messages View is null");
    }

    //listBookmarks.setVisibility(View.GONE);

    imgBabble.setOnClickListener(new View.OnClickListener() 
    {
        @Override
        public void onClick(View v) 
        {
            System.out.println("Babble Clicked");

            babbleShrunkView = babbleLayout.getDrawingCache();
            villeShrunkView = villeLayout.getDrawingCache();
            privateMsgsShrunkView = privateMsgsLayout.getDrawingCache();
            bookmarksShrunkView = bookmarksLayout.getDrawingCache();

            BabbleVilleShrinkView.addBitmap(0, resizeBitmap(200, 200, babbleShrunkView));
            BabbleVilleShrinkView.addBitmap(1, resizeBitmap(200, 200, villeShrunkView));
            BabbleVilleShrinkView.addBitmap(2, resizeBitmap(200, 200, privateMsgsShrunkView));
            BabbleVilleShrinkView.addBitmap(3, resizeBitmap(200, 200, bookmarksShrunkView));

            Gallery gallery = new Gallery(getApplicationContext());
            gallery.setAdapter(new ImageAdapter(getApplicationContext()));
        }
    });
} // End of class

这篇关于在Android的单一活动的多个列表视图?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆