卡住了...需要帮助..带有数组适配器的列表视图

发布于 2024-09-13 04:47:17 字数 1090 浏览 7 评论 0原文

好的,所以我有这个应用程序,它获取一个地址字符串(来自值/xml)并解析它(您当前的位置),重新调整名称、地址和距离。然后它被数组适配器拾取并放在列表视图上。我一生都无法让列表视图接受 onitemclick 来启动另一个活动,在那里我可以启动不同的视图。我确实有它,我在获取行、名称和地址以显示到警报对话框时,但在我努力让它启动一项活动时,我丢失了它。

那么有人有什么想法吗?我正在使用以下调用来制作我的列表和数组。这是精简的,所以假设我拥有所有导入和正确的格式。我知道我只是在这里错过了一些简单的东西......

public class Wf extends ListActivity {
private ArrayList<String> DistanceList;
private ArrayAdapter<String> aa;

 @Override
 public void onCreate(Bundle icicle) {
   super.onCreate(icicle);

   // Bind the ListView to an ArrayList of strings.
   DistanceList = new ArrayList<String>();

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

aa = new ArrayAdapter<String>(getApplicationContext(), 
                                 R.layout.listbox_layout,
                                 DistanceList);
lv.setAdapter(aa);

//Call to get distance... here
}

 public void onListItemClick(ListView parent, View v,int position, long id) {
    ListView lv = (ListView)findViewById(R.id.ListView01);
    Toast.makeText(this, "You clicked", Toast.LENGTH_LONG).show();
  }

Ok, so I have this application that takes a adress strings (from values/xml) and parses it your current position) retuning a name, address and distance away. This is then picked up by an arrayadapter and put up on a listview. I cannot for the life of me get the list view to accept an onitemclick to start another activity, where I can launch a different view. I did have it where I was getting the row, name and address to show through to an alert dialog, but in my efforts to get it to launch an activity, I lost that.

So does anyone have any thoughts? I am using the following call to make my list and and arrays. This is stripped down, so assume I have all the imports and proper formatting. I know I am just missing something simple here...

public class Wf extends ListActivity {
private ArrayList<String> DistanceList;
private ArrayAdapter<String> aa;

 @Override
 public void onCreate(Bundle icicle) {
   super.onCreate(icicle);

   // Bind the ListView to an ArrayList of strings.
   DistanceList = new ArrayList<String>();

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

aa = new ArrayAdapter<String>(getApplicationContext(), 
                                 R.layout.listbox_layout,
                                 DistanceList);
lv.setAdapter(aa);

//Call to get distance... here
}

 public void onListItemClick(ListView parent, View v,int position, long id) {
    ListView lv = (ListView)findViewById(R.id.ListView01);
    Toast.makeText(this, "You clicked", Toast.LENGTH_LONG).show();
  }

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

分开我的手 2024-09-20 04:47:17

来自 ListActivity 文档:

ListActivity 有一个默认布局
由单个全屏列表组成
在屏幕中央。然而,
如果您愿意,您可以自定义
通过设置您自己的视图来进行屏幕布局
使用 setContentView() 进行布局
onCreate()。为此,您自己的看法
必须包含一个 ListView 对象
id“@android:id/list”(或列表,如果
它在代码中)

您的 ListView 没有正确的 ID。您的代码不完整,但我怀疑侦听器未在 ListView 中注册。

From the ListActivity docs:

ListActivity has a default layout that
consists of a single, full-screen list
in the center of the screen. However,
if you desire, you can customize the
screen layout by setting your own view
layout with setContentView() in
onCreate(). To do this, your own view
MUST contain a ListView object with
the id "@android:id/list" (or list if
it's in code)

Your ListView does not have the correct ID. Your code is incomplete but I suspect the listener is not being registered with the ListView.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文