【问题标题】:Getting data from Parse and populate into listview onto a fragment [closed]从 Parse 获取数据并将其填充到列表视图中的片段 [关闭]
【发布时间】:2014-03-03 06:10:55
【问题描述】:

我正在创建一个 android 应用程序,我有一个片段作为 textview 和一个按钮。当您单击该按钮时,您将被带到另一个活动,这是一个要填写的表单,它有一个添加按钮。单击添加按钮时,将保存数据以进行解析,现在的问题是我要检索数据并将其填充到列表视图并在片段中查看。请帮忙。

【问题讨论】:

标签: android parse-platform


【解决方案1】:

使用 Arraylist 和适配器,

您的代码应如下所示:

public class YourActivity extends Activity {

private ListView lv;

public void onCreate(Bundle saveInstanceState) {
     setContentView(R.layout.your_layout);

     lv = (ListView) findViewById(R.id.your_list_view_id);

     // Instanciating an array list (you don't need to do this, 
     // you already have yours).
     ArrayList<String> your_array_list = new ArrayList<String>();
     your_array_list.add("foo");
     your_array_list.add("bar");

     // This is the array adapter, it takes the context of the activity as a 
     // first parameter, the type of list view as a second parameter and your 
     // array as a third parameter.
     ArrayAdapter<String> arrayAdapter = new ArrayAdapter<String>(
             this, 
             android.R.layout.simple_list_item_1,
             your_array_list );

     lv.setAdapter(arrayAdapter); 
  }
}

参考:Populating a ListView using an ArrayList?

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-10-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多