我自定义了一个适配器 但是显示不出来 哪位高手能帮我看下?谢谢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>
解决方案 »
- cursor.getColumnIndex(PhoneLookup.NUMBER);没取到值
- 如何用android实现临近提醒???
- 各位大侠,哪儿可以下载到官方的adb.exe?
- 自定义framelayout 动画在其中不能播放求解
- 关于Android跟MOTO的运行程序
- android socket 传输速度巨慢!!!!
- ubuntu android源代码下载。
- android开发的应用程序,用模拟器可以访问,但是安装到手机上却不行
- Android里如何获取三星S5手机的APN?
- Volley.newRequestQueue闪退
- android2.2 使用TrafficStats.getUidRxBytes(uid[n])获取流量返回-1,请高手指教!
- android 编码那点事
setListAdapter(adapter);
你的adapter呢