【问题标题】:Android ListView understandingAndroid ListView 理解
【发布时间】:2010-11-23 21:03:30
【问题描述】:

我对 ListView 以及如何使用它有疑问。我的问题是我的 listView 只是视图的一部分,我不知道该怎么做。

public class MainActivity extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    ListView myListView = (ListView) findViewById(R.id.ListView01);
    String[] strings = new String[]{"Test1","Test2"};
    ArrayAdapter<String> myArrayAdapter= new ArrayAdapter<String>(this, R.id.ListView01,strings);
    myListView.setAdapter(myArrayAdapter);

我认为问题出在 myArrayAdapter 中的“this”!?

【问题讨论】:

    标签: android android-listview


    【解决方案1】:

    您应该传递给 ArrayAdapter 的布局资源 ID 是用于呈现列表中每个项目的布局,而不是列表本身的布局。 Android 为常见的情况提供了一些布局资源。尝试使用:

    ArrayAdapter<String> myArrayAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, strings);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-05-22
      • 2014-02-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-11-14
      相关资源
      最近更新 更多