我自定义了一个适配器 但是显示不出来 哪位高手能帮我看下?谢谢Sim.java:public class Sim extends ListActivity {
private static String title1[] = new String[] { "张飞", "关于", "种管理", "诸葛亮",
"与非" };
private static String info1[] = new String[] { "介绍", "介绍", "介绍", "介绍", "介绍" };
private static int resId[] = new int[] { R.drawable.icon, R.drawable.icon,
R.drawable.icon, R.drawable.icon, R.drawable.icon };
LayoutInflater lf;
private MyAdapter adapter; protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState);
List<View> list = new ArrayList<View>();
list.add(getLayoutInflater().inflate(R.layout.sim, null));
setListAdapter(adapter); } private class MyAdapter extends BaseAdapter {
private Context context; public MyAdapter(Context context) {
this.context = context;
lf = (LayoutInflater) context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
} public int getCount() { return title1.length;
} public Object getItem(int position) { return title1[position];
} public long getItemId(int position) { return position;
} public View getView(int position, View convertView, ViewGroup parent) {
LinearLayout linearLayout = (LinearLayout) lf.inflate(R.layout.sim,
null);
ImageView iv = (ImageView) linearLayout.findViewById(R.id.iv);
TextView title = (TextView) linearLayout.findViewById(R.id.title);
TextView info = (TextView) linearLayout.findViewById(R.id.info);
Button bt = (Button) linearLayout.findViewById(R.id.bt);
bt.setOnClickListener(new OnClickListener() { public void onClick(View v) {
Toast.makeText(Sim.this, "这是", Toast.LENGTH_LONG).show();
} });
iv.setImageResource(resId[position]);
title.setText(title1[position]);
info.setText(info1[position]);
return linearLayout;
} }}
Manifest:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="ds.ds" android:versionCode="1" android:versionName="1.0">
<application android:icon="@drawable/icon" android:label="@string/app_name">
<activity android:name=".Sim" android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".Main" android:label="@string/app_name">
</activity> </application>
</manifest>
private static String title1[] = new String[] { "张飞", "关于", "种管理", "诸葛亮",
"与非" };
private static String info1[] = new String[] { "介绍", "介绍", "介绍", "介绍", "介绍" };
private static int resId[] = new int[] { R.drawable.icon, R.drawable.icon,
R.drawable.icon, R.drawable.icon, R.drawable.icon };
LayoutInflater lf;
private MyAdapter adapter; protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState);
List<View> list = new ArrayList<View>();
list.add(getLayoutInflater().inflate(R.layout.sim, null));
setListAdapter(adapter); } private class MyAdapter extends BaseAdapter {
private Context context; public MyAdapter(Context context) {
this.context = context;
lf = (LayoutInflater) context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
} public int getCount() { return title1.length;
} public Object getItem(int position) { return title1[position];
} public long getItemId(int position) { return position;
} public View getView(int position, View convertView, ViewGroup parent) {
LinearLayout linearLayout = (LinearLayout) lf.inflate(R.layout.sim,
null);
ImageView iv = (ImageView) linearLayout.findViewById(R.id.iv);
TextView title = (TextView) linearLayout.findViewById(R.id.title);
TextView info = (TextView) linearLayout.findViewById(R.id.info);
Button bt = (Button) linearLayout.findViewById(R.id.bt);
bt.setOnClickListener(new OnClickListener() { public void onClick(View v) {
Toast.makeText(Sim.this, "这是", Toast.LENGTH_LONG).show();
} });
iv.setImageResource(resId[position]);
title.setText(title1[position]);
info.setText(info1[position]);
return linearLayout;
} }}
Manifest:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="ds.ds" android:versionCode="1" android:versionName="1.0">
<application android:icon="@drawable/icon" android:label="@string/app_name">
<activity android:name=".Sim" android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".Main" android:label="@string/app_name">
</activity> </application>
</manifest>
解决方案 »
- [新手求助]sdcard权限为d-----
- 导apidemo的时候为什么工程 报红叉。
- [求助]GridView载入过慢问题
- camera缩放问题
- 通过Intent 启动bt setting应用
- android openGL多纹理
- 关于android socket通信接收服务器数据问题
- android控件WebView处理frameset时背景不能透明
- jpsip发起多方对话错误:Description: Too many objects of the specified type (PJ_ETOOMANY)
- Android短信验证
- android2.2 使用TrafficStats.getUidRxBytes(uid[n])获取流量返回-1,请高手指教!
- android 编码那点事
setListAdapter(adapter);
你的adapter呢