android SimpleAdapter绑定onItemClickListener事件求解
我需要的效果就是图片上的每一项点击后都会传一个网址在另一个activity里打开,但是不知道怎么绑定onItemClickListener事件我需要把网址塞到Intent...
我需要的效果就是图片上的每一项点击后都会传一个网址在另一个activity里打开,但是不知道怎么绑定onItemClickListener事件
我需要把网址塞到Intent里面传到下一个Activity里打开,下面代码中的map01.put("html", )就是我的网址
package com.jerehsoft.sale.main;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ListView;
import android.widget.SimpleAdapter;
import com.jerehsoft.platform.R;
import com.jerehsoft.platform.activity.JEREHBaseActivity;
import com.jerehsoft.platform.activity.JEREHBaseSimpleListActivity;
import com.jerehsoft.platform.activity.utils.DataControlResult;
public class MainActivity extends JEREHBaseActivity
{
private ListView qiye_list;
protected DataControlResult controlResult; // TODO 表单对应操作结果类
private int syTag=-1;//TODO 同步标签
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main_layout);
qiye_list=(ListView)findViewById(R.id.qiye_list);
String[] qiye = new String[] {};
qiye = getResources().getStringArray(R.array.qiye06);
List<Map<String, Object>> qiyelist = new ArrayList<Map<String, Object>>();
for (int i = 0; i < qiye.length; i+=3){
Map<String, Object> map01 = new HashMap<String, Object>();
map01.put("title", qiye[i]);
map01.put("pubtime", qiye[i+1]);
map01.put("html", qiye[i+2]);
map01.put("pic", R.drawable.logo21);
qiyelist.add(map01);
}
SimpleAdapter adapter = new SimpleAdapter(
this,qiyelist,R.layout.qiye__list_layout,new String[]{"pic","title","pubtime"},new int[]{R.id.image,R.id.qiye_title,R.id.qiye_pubtime});
qiye_list.setAdapter(adapter);
qiye_list.setOnItemClickListener(new OnItemClickListener(){
public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
long arg3) {
// TODO Auto-generated method stub
HashMap<String, Object> item=(HashMap<String, Object>) arg0.getItemAtPosition(arg2);
//这里面该怎么继续写
}});
}
} 展开
我需要把网址塞到Intent里面传到下一个Activity里打开,下面代码中的map01.put("html", )就是我的网址
package com.jerehsoft.sale.main;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ListView;
import android.widget.SimpleAdapter;
import com.jerehsoft.platform.R;
import com.jerehsoft.platform.activity.JEREHBaseActivity;
import com.jerehsoft.platform.activity.JEREHBaseSimpleListActivity;
import com.jerehsoft.platform.activity.utils.DataControlResult;
public class MainActivity extends JEREHBaseActivity
{
private ListView qiye_list;
protected DataControlResult controlResult; // TODO 表单对应操作结果类
private int syTag=-1;//TODO 同步标签
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main_layout);
qiye_list=(ListView)findViewById(R.id.qiye_list);
String[] qiye = new String[] {};
qiye = getResources().getStringArray(R.array.qiye06);
List<Map<String, Object>> qiyelist = new ArrayList<Map<String, Object>>();
for (int i = 0; i < qiye.length; i+=3){
Map<String, Object> map01 = new HashMap<String, Object>();
map01.put("title", qiye[i]);
map01.put("pubtime", qiye[i+1]);
map01.put("html", qiye[i+2]);
map01.put("pic", R.drawable.logo21);
qiyelist.add(map01);
}
SimpleAdapter adapter = new SimpleAdapter(
this,qiyelist,R.layout.qiye__list_layout,new String[]{"pic","title","pubtime"},new int[]{R.id.image,R.id.qiye_title,R.id.qiye_pubtime});
qiye_list.setAdapter(adapter);
qiye_list.setOnItemClickListener(new OnItemClickListener(){
public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
long arg3) {
// TODO Auto-generated method stub
HashMap<String, Object> item=(HashMap<String, Object>) arg0.getItemAtPosition(arg2);
//这里面该怎么继续写
}});
}
} 展开
4个回答
展开全部
后面需要做的就是把这些放到intent里面,之后startActivity就可以啦,当然,你用来接收的activity需要解析这些参数,例如:
Intent i = new Intent();
......
i.putExtra("title", (String) item.get("title"));
i.putExtra("pubtime", (String) item.get("pubtime"));
i.putExtra("html", (String) item.get("html"));
i.putExtra("pic", R.drawable.logo21);
......
startActivity(i);
Intent i = new Intent();
......
i.putExtra("title", (String) item.get("title"));
i.putExtra("pubtime", (String) item.get("pubtime"));
i.putExtra("html", (String) item.get("html"));
i.putExtra("pic", R.drawable.logo21);
......
startActivity(i);
展开全部
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ListView;
import android.widget.SimpleAdapter;
public class ListViewDeom1 extends Activity {
ListView listview;
List<Map<String,Object>> myData;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
myData=new ArrayList<Map<String,Object>>();
listview=(ListView)findViewById(R.id.listview);
for(int i=0;i<8;i++){
Map<String, Object> map = new HashMap<String, Object>();
map.put("title", "title"+i);
map.put("content", "content"+i);
map.put("picture", R.drawable.kenan);
map.put("url", "http://www.baidu.com");
myData.add(map);
}
SimpleAdapter adapter=new SimpleAdapter(this, myData, R.layout.vlist,
new String[]{"title","content","picture"}, new int[]{R.id.title,R.id.content,R.id.picture});
listview.setAdapter(adapter);
listview.setOnItemClickListener(new OnItemClickListener(){
@Override
public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
long arg3) {
String url=(String) myData.get(arg2).get("url");
Uri uri=Uri.parse(url);
Intent intent=new Intent(Intent.ACTION_VIEW, uri);
ListViewDeom1.this.startActivity(intent);
}
});
}
}
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ListView;
import android.widget.SimpleAdapter;
public class ListViewDeom1 extends Activity {
ListView listview;
List<Map<String,Object>> myData;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
myData=new ArrayList<Map<String,Object>>();
listview=(ListView)findViewById(R.id.listview);
for(int i=0;i<8;i++){
Map<String, Object> map = new HashMap<String, Object>();
map.put("title", "title"+i);
map.put("content", "content"+i);
map.put("picture", R.drawable.kenan);
map.put("url", "http://www.baidu.com");
myData.add(map);
}
SimpleAdapter adapter=new SimpleAdapter(this, myData, R.layout.vlist,
new String[]{"title","content","picture"}, new int[]{R.id.title,R.id.content,R.id.picture});
listview.setAdapter(adapter);
listview.setOnItemClickListener(new OnItemClickListener(){
@Override
public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
long arg3) {
String url=(String) myData.get(arg2).get("url");
Uri uri=Uri.parse(url);
Intent intent=new Intent(Intent.ACTION_VIEW, uri);
ListViewDeom1.this.startActivity(intent);
}
});
}
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
楼主的问题我也遇到过~其实似乎忘记了一点..时间侦听只能在UI线程里执行
换句话说你在Adapter里面是不能进行侦听的~所以你要在外面
qiye_list.setonItemClickListener 这样生成出来的监听里面就有Adapter里面的position然后你再switch进行分类就OK了
换句话说你在Adapter里面是不能进行侦听的~所以你要在外面
qiye_list.setonItemClickListener 这样生成出来的监听里面就有Adapter里面的position然后你再switch进行分类就OK了
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
岚风宝宝 说的就可以
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询
广告 您可能关注的内容 |