当前位置:首页 » 安卓系统 » android列表显示

android列表显示

发布时间: 2025-02-07 17:01:19

1. android 怎listview一行显示3个数据

一般的SimpleAdapter就可以啊

private ListView lv1;//布局中的ListView
lv1 = (ListView) findViewById(R.id.sim_list);
List<Map<String,String>> mLists = new ArrayList<Map<String,String>>();
//为列表添加数据(为了方便数据都做成一样的了)
for(int i=0;i<21;i++) {
Map<String, String> map = new HashMap<String, String>();
map.put("title", "小宗");
map.put("info", "电台DJ");
map.put("age", "21");
mLists.add(map);
}
/**
* SimpleAdapter信息配置
* R.layout.simple_item对应一个ListView显示的内容布局
* String对应map中放置的键值对名称
* int对应内容布局的控件id
*/
SimpleAdapter adapter = new SimpleAdapter(Context, mLists,
R.layout.simple_item, new String[] { "title", "info", "age"},
new int[] {R.id.title, R.id.info, R.id.age});
//为ListView添加对应的Adapter
lv1.setAdapter(adapter);

xml布局文件
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal" >

<TextView
android:id="@+id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:textSize="18sp" />

<TextView
android:id="@+id/info"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:textSize="16sp" />

<TextView
android:id="@+id/age"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:textSize="16sp" />

</LinearLayout>
想加多少,添加就行了
复杂点的就用BaseAdapter,不过单纯想加数据的话,用SimpleAdapter简单

2. android 中listview是怎么用的

表的显示需要三个元素:
1.ListVeiw 用来展示列表的View。
2.适配器 用来把数据映射到ListView上的中介。
3.数据 具体的将被映射的字符串,图片,或者基本组件。
根据列表的适配器类型,列表分为三种,ArrayAdapter,SimpleAdapter和SimpleCursorAdapter
其中以ArrayAdapter最为简单,只能展示一行字。SimpleAdapter有最好的扩充性,可以自定义出各种效果。SimpleCursorAdapter可以认为是SimpleAdapter对数据库的简单结合,可以方面的把数据库的内容以列表的形式展示出来。
我们从最简单的ListView开始:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30

/**
* @author allin
*
*/
public class MyListView extends Activity {

private ListView listView;
//private List<String> data = new ArrayList<String>();
@Override
public void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);

listView = new ListView(this);
listView.setAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_expandable_list_item_1,getData()));
setContentView(listView);
}

private List<String> getData(){

List<String> data = new ArrayList<String>();
data.add("测试数据1");
data.add("测试数据2");
data.add("测试数据3");
data.add("测试数据4");

return data;
}
}

上面代码使用了ArrayAdapter(Context context, int textViewResourceId, List<T> objects)来装配数据,要装配这些数据就需要一个连接ListView视图对象和数组数据的适配器来两者的适配工作,ArrayAdapter的构造需要三个参数,依次为this,布局文件(注意这里的布局文件描述的是列表的每一行的布局,android.R.layout.simple_list_item_1是系统定义好的布局文件只显示一行文字,数据源(一个List集合)。同时用setAdapter()完成适配的最后工作。运行后的现实结构如下 :

SimpleCursorAdapter
sdk的解释是这样的:An easy adapter to map columns from a cursor to TextViews or ImageViews defined in an XML file. You can specify which columns you want, which views you want to display the columns, and the XML file that defines the appearance of these views。简单的说就是方便把从游标得到的数据进行列表显示,并可以把指定的列映射到对应的TextView中。

3. 如何将Android数据库中表格的某一列在下拉列表中显示

请参考SDK下APIDemo例子,里面有详细的介绍,路径platforms/android-4(我的是1.6的)/samples/ApiDemos
,打开应用操作步骤如下Views-->List,里面有很多中列表,你自己选择;
关于新建item,如果你要实现自己的样式,可以自定Adapter;你提问中android.R.layout.simple_spinner_item和别人的item是一个作用,就是列表中每一行的样式,有什么问题再hi我

4. android 如何让应用程序在全部应用程序列表里显示跟隐藏!

之前有个客户的需求特别怪,要求应用不在全部应用程序列表里显示,通过拨打指定的电话号码形式启动应用,开始的想发就是在manifest.xml里的第一个activity里不添加<action android:name=android.intent.action.MAIN / <category android:name=android.intent.category.LAUNCHER /这两个intentfilter。发现在4.0以上的版本就会出现错误!4.0会认为你这个是不安全的信息,无法启动。后来在PackageManager里发现了setComponentEnabledSetting这个方法,可以达到效果!看代码吧!

5. android listView 显示不全,为什么

重写LinearLayout显示列表
import android.content.Context;
import android.util.AttributeSet;
import android.util.Log;
import android.util.TypedValue;
import android.view.View;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.BaseAdapter;
import android.widget.LinearLayout;

/***
*
* @author FreePC
*
*/
public class LinearLayoutForListView extends LinearLayout
{
private BaseAdapter adapter;
private OnItemClickListener onItemClickListener;

/**
* 通过 Java代码 实例化
* @param context
*/
public LinearLayoutForListView(Context context)
{
super(context);
//设置LinearLayoutForListView为垂直布局,否者默认为水平布局,容易疏忽导致子项显示不全
LinearLayoutForListView.this.setOrientation(LinearLayout.VERTICAL);
}

/**
* 此构造函数可以允许我们通过 XML的方式注册 控件
* @param context
* @param attrs
*/
public LinearLayoutForListView(Context context, AttributeSet attrs)
{
super(context, attrs);
LinearLayoutForListView.this.setOrientation(LinearLayout.VERTICAL);
}

/**
* 设置适配器
*
* @param adpater
*/
public void setAdapter(BaseAdapter adpater)
{
this.adapter = adpater;
bindLinearLayout();
}

/**
* 获取适配器Adapter
*
* @return adapter
*/
public BaseAdapter getAdpater()
{
return adapter;
}

/**
* 绑定布局:将每个子项的视图view添加进此线性布局LinearLayout中
*/
public void bindLinearLayout()
{
int count = adapter.getCount();
for (int i = 0; i < count; i++)
{
View v = adapter.getView(i, null, null);

if (i != count - 1)
{ //添加每项item之间的分割线
v = addLine(v);
}
addView(v, i);
}
setItemClickListener();
Log.v("countTAG", "" + count);
}

/**
* 添加每项item之间的分割线
*
* @param view
* @return
*/
public View addLine(View view)
{
//分割线view
View lineView = new View(view.getContext());

// 将数据从dip(即dp)转换到px,第一参数为数据原单位(此为DIP),第二参数为要转换的数据值
float fPx = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP,
(float) 0.5, view.getResources().getDisplayMetrics());
int iPx = Math.round(fPx);

LayoutParams layoutParams = new LayoutParams(
LinearLayout.LayoutParams.MATCH_PARENT, iPx);
lineView.setLayoutParams(layoutParams);
lineView.setBackgroundColor(view.getSolidColor());

LinearLayout ly = new LinearLayout(view.getContext());
ly.setOrientation(LinearLayout.VERTICAL);

ly.addView(view);
ly.addView(lineView);

return ly;
}

/**
* 设置点击子项事件监听对象
* @param onItemClickListener
*/
public void setOnItemClickListener(OnItemClickListener onItemClickListener)
{
this.onItemClickListener = onItemClickListener;
setItemClickListener();
}

/**
* 获取点击子项事件监听对象
* @return
*/
public OnItemClickListener getOnItemClickListener()
{
return onItemClickListen

热点内容
好矿云服务器 发布:2025-02-07 19:54:31 浏览:947
java电话簿 发布:2025-02-07 19:49:26 浏览:795
超级脚本制作 发布:2025-02-07 19:31:30 浏览:486
怎么查看支付宝的账号密码 发布:2025-02-07 19:26:48 浏览:16
惠普服务器查看ip指令 发布:2025-02-07 19:26:47 浏览:434
算法设计模式 发布:2025-02-07 19:15:52 浏览:745
服务器1u能连接几台电脑 发布:2025-02-07 18:50:02 浏览:153
立人编译 发布:2025-02-07 18:48:32 浏览:765
日产途达四驱的有哪些配置 发布:2025-02-07 18:42:02 浏览:832
服务器搭建镜像站 发布:2025-02-07 18:41:55 浏览:377