gpt4 book ai didi

android - 带有 4 个 TextView 的 ListView

转载 作者:行者123 更新时间:2023-11-29 16:14:12 24 4
gpt4 key购买 nike

我必须创建一个 ListView ,其中单行有 4 个 TextView 。我的问题是我不明白如何使用适配器,所以有人可以帮助我了解适配器及其实现吗?

这是我的布局

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center"
android:orientation="vertical" >




<TextView
android:id="@+id/textView1"
android:layout_width="192dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginBottom="20dp"
android:text="Grazie per aver parcheggiato da noi!"
android:textAppearance="?android:attr/textAppearanceMedium" />

<ListView
android:id="@+id/mylist"
android:layout_width="match_parent"
android:layout_height="wrap_content"
</ListView>


<Button
android:id="@+id/btnEsci"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="Torna a scelta" />

</LinearLayout>

这是单行(single_feed)

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >

<!-- TEXT OF FEED -->

<TextView
android:id="@+id/txtId"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Numero macchina: #"
android:textAppearance="?android:attr/textAppearanceMedium" />

<TextView
android:id="@+id/txtTarga"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Targa: #"
android:textAppearance="?android:attr/textAppearanceMedium" />

<TextView
android:id="@+id/txtOra"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Ora ingresso: #"
android:textAppearance="?android:attr/textAppearanceMedium" />


<TextView
android:id="@+id/txtCosto"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Prezzo uscita: #"
android:textAppearance="?android:attr/textAppearanceMedium"
android:lines="1"
/>

这是我的适配器:

public class MioAdapter extends ArrayAdapter<String> {
private final Context context;
private final String[] values;

public MioAdapter(Context context, String[] values) {
super(context, R.layout.single_feed, values);
this.context = context;
this.values = values;
}

@Override
public View getView(int position, View convertView, ViewGroup parent) {
LayoutInflater inflater = (LayoutInflater) context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View rowView = inflater.inflate(R.layout.single_feed, parent, false);
TextView textView = (TextView) rowView.findViewById(R.id.label);
textView.setText(values[position]);
// Change the icon for Windows and iPhone


return rowView;
}

最后这是我的 Activity :

public class checkout extends Activity{
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
//apro la view
super.onCreate(savedInstanceState);
setContentView(R.layout.checkout);

//gestsco l'adapter per creare la lista
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
String[] values = new String[] { "Android", "iPhone", "WindowsMobile",
"Blackberry", "WebOS", "Ubuntu", "Windows7", "Max OS X",
"Linux", "OS/2" };
MioAdapter adapter = new MioAdapter(this, values);
setListAdapter(adapter);
};

有人可以帮我处理适配器吗?感谢所有可以帮助我解决这个简单问题的人:)

最佳答案

See this Custom listView

行中有两个 TextView ,您只需添加四个 TextView ,因此添加行布局文件。并在 TextView 中添加 android:maxLines="1" 用于单行 TextView 。

关于android - 带有 4 个 TextView 的 ListView ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10700754/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com