解决方案 »
- service莫名新启动的问题请教
- 做过仿IPhone滑动开关的请进。
- 菜鸟问题,莫要见笑。请问统一个系统,B/S版本和一个安卓客户端版本可以访问同一个服务器端吗?
- 请教,通过互联网服务器端怎么向终端发送文件?
- 250*250的图片在屏幕上显示的长度
- android关于dialog的关闭问题
- Android CTS 兼容性测试
- linux下 下载android源代码遇到墙的问题怎么办
- 求助,想用c++访问android文件并处理。java通过jni得到结果
- MAC Android studio 打开报错com.intellij.ide.plugins.PluginManager$StartupAbortedExce
- 如何将数据库中的数据显示到文本控件中?
- 请教个初级问题,环境搭建
private ListView mListView;
private SimpleAdapter mAdapter;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
//
ArrayList<Map<String,Object>> mList= new ArrayList<Map<String, Object>>();
Map<String, Object> map = new HashMap<String, Object>();
map.put("title", "G1");
map.put("info", "google 1");
map.put("img", R.drawable.icon);
mList.add(map);
map = new HashMap<String, Object>();
map.put("title", "G2");
map.put("info", "google 2");
map.put("img", R.drawable.icon);
mList.add(map);
map = new HashMap<String, Object>();
map.put("title", "G3");
map.put("info", "google 3");
map.put("img", R.drawable.icon);
mList.add(map);;
//
mAdapter=new SimpleAdapter(this,mList,R.layout.sss,new String[]{"title","info","img"},new int[]{R.id.textview1,R.id.textview2,R.id.imageview1});
mListView.setAdapter(mAdapter);
主窗口
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/hello"
/>
<ListView
android:id="@+id/listview1"
android:layout_height="wrap_content"
android:layout_width="match_parent"/>
</LinearLayout>
ListViewItem布局
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal" android:layout_width="fill_parent"
android:layout_height="fill_parent">
<ImageView
android:id="@+id/imageview1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="5px"/>
<LinearLayout android:orientation="vertical"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<TextView android:id="@+id/textview1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#FFFFFFFF"
android:textSize="22px"
android:text="textview1"/>
<TextView android:id="@+id/textview2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#FFFFFFFF"
android:textSize="13px"
android:text="textview2"/>
</LinearLayout>
</LinearLayout>
请问有人知道问什么吗??!!
private SimpleAdapter mAdapter;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);//mListView必须在R.layout.main布局中
mListView = (ListView)findViewById(R.id.listview1);
//
ArrayList<Map<String,Object>> mList= new ArrayList<Map<String, Object>>();
Map<String, Object> map = new HashMap<String, Object>();
map.put("title", "G1");
map.put("info", "google 1");
map.put("img", R.drawable.icon);
mList.add(map);
map = new HashMap<String, Object>();
map.put("title", "G2");
map.put("info", "google 2");
map.put("img", R.drawable.icon);
mList.add(map);
map = new HashMap<String, Object>();
map.put("title", "G3");
map.put("info", "google 3");
map.put("img", R.drawable.icon);
mList.add(map);;
//
mAdapter=new SimpleAdapter(this,mList,R.layout.sss(该参数为ListViewItem的布局),new String[]{"title","info","img"},new int[]{R.id.textview1,R.id.textview2,R.id.imageview1});
mListView.setAdapter(mAdapter);
可是我还有一个SimpleCursorAdapter的小程序,这次Widget都有定义,可是同样发生了RUNTimeException的异常,能否帮忙查看。我已经通过检测发现错误出在
SimpleCursorAdapter adapter = new SimpleCursorAdapter(this, R.layout.list, mCursor, new String[]{ myHelper.col2_name }, new int[]{ R.id.listTextView1 });这句。因为前面的输出都有输出。下面是简要代码。
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
//
mEditText=(EditText)findViewById(R.id.edittext1);
mListView=(ListView)findViewById(R.id.listview1);
//
mHelper=new myHelper(this);
mCursor=mHelper.select();
//startManagingCursor(mCursor);
for(int i=0;i<mCursor.getColumnCount();i++)
{
System.out.println("Column "+i+":"+mCursor.getColumnName(i));
}
//
SimpleCursorAdapter adapter = new SimpleCursorAdapter(this, R.layout.list, mCursor, new String[]{ myHelper.col2_name }, new int[]{ R.id.listTextView1 });
if(adapter!=null)System.out.println("adapter");
mListView.setAdapter(adapter); mListView.setOnItemClickListener
(new AdapterView.OnItemClickListener()
{ @Override
public void onItemClick
(AdapterView<?> arg0, View arg1, int arg2, long arg3)
{
System.out.println("onItemClick arg2:"+arg2+" arg3:"+arg3);
mCursor.moveToPosition(arg2);
_id = mCursor.getInt(0);
System.out.println("In ItemClick:"+_id);
mEditText.setText(mCursor.getString(1));
} });
mListView.setOnItemSelectedListener
(new AdapterView.OnItemSelectedListener()
{
@Override
public void onItemSelected
(AdapterView<?> arg0, View arg1, int arg2, long arg3)
{
System.out.println("onItemSelect arg2:"+arg2+" arg3:"+arg3);
SQLiteCursor sc = (SQLiteCursor) arg0.getSelectedItem();
_id = sc.getInt(0);
System.out.println("ItemSelected:"+_id);
mEditText.setText(sc.getString(1));
}
@Override
public void onNothingSelected(AdapterView<?> arg0)
{
}
});
}