不同的图标的列表视图视图、图标、不同、列表

2023-09-04 12:58:18 作者:苦口甜心

我要创建的列表图,其中每个项目得到一个单独的图标沿右侧。我已经写了code,但它不工作?我该如何进行呢? 应用程序崩溃

code

 公共类LoginMenu扩展ListActivity
{

TextView中的mainText,潜台词;
QuickContactBadge图标;

私有静态最后的String []菜单项= {可用性,消息,
问候,地址簿,电话,设置};

@覆盖
保护无效的onCreate(包savedInstanceState)
{
// TODO自动生成方法存根
super.onCreate(savedInstanceState);
的setContentView(R.layout.menu);
的mainText =(TextView中)findViewById(R.id.tvMainText);
潜台词=(TextView中)findViewById(R.id.tvSubText);
setListAdapter(新IconicAdapter());
}
类IconicAdapter扩展ArrayAdapter<字符串>
{
公共IconicAdapter()
{
超(LoginMenu.this,R.layout.menu,R.id.tvMainText,菜单项);
// TODO自动生成构造函数存根
}
@覆盖
公共查看getView(INT位置,查看convertView,父母的ViewGroup)
{
// TODO自动生成方法存根
查看排= super.getView(位置,convertView,父母);
图标=(QuickContactBadge)findViewById(R.id.iContactBadge);
如果(菜单项[0]!= NULL)
{
icon.setImageResource(R.drawable.menu_availability);
}
否则,如果(菜单项[1]!= NULL)
{
icon.setImageResource(R.drawable.menu_messages);
}
否则,如果(菜单项[2]!= NULL)
{
icon.setImageResource(R.drawable.menu_greetings);
}
否则,如果(菜单项[3]!= NULL)
{
icon.setImageResource(R.drawable.menu_contacts);
}
否则,如果(菜单项[4]!= NULL)
{
icon.setImageResource(R.drawable.menu_calls);
}
否则,如果(菜单项[5]!= NULL)
{
icon.setImageResource(R.drawable.menu_settings);
}
返回(行);
}
}
}
 

图片我的XML文件中包含一个图像,TextView的,并根据下

图安排的另一个潜台词

logcat的

  4月10日至11号:46:15.088:E / AndroidRuntime(726):致命异常:主要
四月10日至11日:46:15.088:E / AndroidRuntime(726):java.lang.RuntimeException的:无法启动的活动ComponentInfo {com.example.avst.callx pressmobile / com.example.avst.callx pressmobile.MenuScreen}:java.lang.RuntimeException的:你的内容必须有一个ListView,其id属性是'android.R.id.list
四月10日至11日:46:15.088:E / AndroidRuntime(726):在android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2059)
四月10日至11日:46:15.088:E / AndroidRuntime(726):在android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2084)
四月10日至11日:46:15.088:E / AndroidRuntime(726):在android.app.ActivityThread.access $ 600(ActivityThread.java:130)
四月10日至11日:46:15.088:E / AndroidRuntime(726):在android.app.ActivityThread $ H.handleMessage(ActivityThread.java:1195)
四月10日至11日:46:15.088:E / AndroidRuntime(726):在android.os.Handler.dispatchMessage(Handler.java:99)
四月10日至11日:46:15.088:E / AndroidRuntime(726):在android.os.Looper.loop(Looper.java:137)
四月10日至11日:46:15.088:E / AndroidRuntime(726):在android.app.ActivityThread.main(ActivityThread.java:4745)
四月10日至11日:46:15.088:E / AndroidRuntime(726):在java.lang.reflect.Method.invokeNative(本机方法)
四月10日至11日:46:15.088:E / AndroidRuntime(726):在java.lang.reflect.Method.invoke(Method.java:511)
四月10日至11日:46:15.088:E / AndroidRuntime(726):在com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:786)
四月10日至11日:46:15.088:E / AndroidRuntime(726):在com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
四月10日至11日:46:15.088:E / AndroidRuntime(726):在dalvik.system.NativeStart.main(本机方法)
四月10日至11日:46:15.088:E / AndroidRuntime(726):java.lang.RuntimeException的:你的内容必须有一个ListView,其id属性是'android.R.id.list产生的原因
四月10日至11日:46:15.088:E / AndroidRuntime(726):在android.app.ListActivity.onContentChanged(ListActivity.java:243)
四月10日至11日:46:15.088:E / AndroidRuntime(726):在com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:259)
四月10日至11日:46:15.088:E / AndroidRuntime(726):在android.app.Activity.setContentView(Activity.java:1867)
四月10日至11日:46:15.088:E / AndroidRuntime(726):在com.example.avst.callx pressmobile.MenuScreen.onCreate(MenuScreen.java:22)
四月10日至11日:46:15.088:E / AndroidRuntime(726):在android.app.Activity.performCreate(Activity.java:5008)
四月10日至11日:46:15.088:E / AndroidRuntime(726):在android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1079)
四月10日至11日:46:15.088:E / AndroidRuntime(726):在android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2023)
四月10日至11日:46:15.088:E / AndroidRuntime(726):11 ...更多
 

解决方案 UI设计之安卓规范列表视图图标制作

您可以简单的code在这里,它显示的图像和列表的每一行中一些文本:

http://www.mkyong.com/android/android-listview-example/

,但如果行数是高的,如果每行中的图像要被从服务器中提取那么你最好使用这样的:

https://github.com/thest1/LazyList

I have to create a list view , with each item getting a separate icon along the right hand side. I have written a code , but its not working ? how do I proceed ? application crashes

CODE

public class LoginMenu extends ListActivity
{

TextView maintext, subtext;
QuickContactBadge icon;

private static final String[] menuitems = { "Availability", "Messages",
"Greetings", "Address Book", "Calls", "Settings" };

@Override
protected void onCreate(Bundle savedInstanceState)
{
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.menu);
maintext = (TextView) findViewById(R.id.tvMainText);
subtext = (TextView) findViewById(R.id.tvSubText);
setListAdapter(new IconicAdapter());    
}    
class IconicAdapter extends ArrayAdapter<String>
{    
public IconicAdapter()
{
super(LoginMenu.this, R.layout.menu, R.id.tvMainText, menuitems);
// TODO Auto-generated constructor stub
}   
@Override
public View getView(int position, View convertView, ViewGroup parent)
{
// TODO Auto-generated method stub
View row = super.getView(position, convertView, parent);
icon = (QuickContactBadge) findViewById(R.id.iContactBadge);
if (menuitems[0] != null)
{
icon.setImageResource(R.drawable.menu_availability);
}
else if (menuitems[1] != null)
{
icon.setImageResource(R.drawable.menu_messages);
}    
else if (menuitems[2] != null)
{
icon.setImageResource(R.drawable.menu_greetings);
}
else if (menuitems[3] != null)
{
icon.setImageResource(R.drawable.menu_contacts);    
}
else if (menuitems[4] != null)
{
icon.setImageResource(R.drawable.menu_calls);
}
else if (menuitems[5] != null)
{
icon.setImageResource(R.drawable.menu_settings);
}
return (row);
}    
}
}

IMAGE My XML file contains a image , textview and another subtext arranged according to the figure below

LOGCAT

10-11 04:46:15.088: E/AndroidRuntime(726): FATAL EXCEPTION: main
10-11 04:46:15.088: E/AndroidRuntime(726): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.avst.callxpressmobile/com.example.avst.callxpressmobile.MenuScreen}: java.lang.RuntimeException: Your content must have a ListView whose id attribute is 'android.R.id.list'
10-11 04:46:15.088: E/AndroidRuntime(726):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2059)
10-11 04:46:15.088: E/AndroidRuntime(726):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2084)
10-11 04:46:15.088: E/AndroidRuntime(726):  at android.app.ActivityThread.access$600(ActivityThread.java:130)
10-11 04:46:15.088: E/AndroidRuntime(726):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1195)
10-11 04:46:15.088: E/AndroidRuntime(726):  at android.os.Handler.dispatchMessage(Handler.java:99)
10-11 04:46:15.088: E/AndroidRuntime(726):  at android.os.Looper.loop(Looper.java:137)
10-11 04:46:15.088: E/AndroidRuntime(726):  at android.app.ActivityThread.main(ActivityThread.java:4745)
10-11 04:46:15.088: E/AndroidRuntime(726):  at java.lang.reflect.Method.invokeNative(Native Method)
10-11 04:46:15.088: E/AndroidRuntime(726):  at java.lang.reflect.Method.invoke(Method.java:511)
10-11 04:46:15.088: E/AndroidRuntime(726):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
10-11 04:46:15.088: E/AndroidRuntime(726):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
10-11 04:46:15.088: E/AndroidRuntime(726):  at dalvik.system.NativeStart.main(Native Method)
10-11 04:46:15.088: E/AndroidRuntime(726): Caused by: java.lang.RuntimeException: Your content must have a ListView whose id attribute is 'android.R.id.list'
10-11 04:46:15.088: E/AndroidRuntime(726):  at android.app.ListActivity.onContentChanged(ListActivity.java:243)
10-11 04:46:15.088: E/AndroidRuntime(726):  at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:259)
10-11 04:46:15.088: E/AndroidRuntime(726):  at android.app.Activity.setContentView(Activity.java:1867)
10-11 04:46:15.088: E/AndroidRuntime(726):  at com.example.avst.callxpressmobile.MenuScreen.onCreate(MenuScreen.java:22)
10-11 04:46:15.088: E/AndroidRuntime(726):  at android.app.Activity.performCreate(Activity.java:5008)
10-11 04:46:15.088: E/AndroidRuntime(726):  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1079)
10-11 04:46:15.088: E/AndroidRuntime(726):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2023)
10-11 04:46:15.088: E/AndroidRuntime(726):  ... 11 more

解决方案

You can get simple Code here, which shows an image and some text in each row of the list:

http://www.mkyong.com/android/android-listview-example/

but if the number of rows is high, and if the image in each row is to be fetched from a server then you better use this:

https://github.com/thest1/LazyList