gpt4 book ai didi

Android ImageButton ListView

转载 作者:行者123 更新时间:2023-11-29 15:47:24 25 4
gpt4 key购买 nike

如何做出这样的东西?

image

对于我的应用程序,我想要一些图像按钮列表,如果我按下一个按钮,我想做一些事情。我真的在所有谷歌上搜索找到它,我找到了一些例子,但它们都太复杂了,而且有更多的细节

谁能给我一个关于如何制作简单的图像按钮列表的教程或示例?

最佳答案

制作按钮列表的一个简单方法是创建一个适配器。你可以通过做一些事情来使用它 list ButtonListAdapter buttonListAdapter = new ButtonListAdapter(context, List<"of whatever you send in">);.然后使用列表 list.setAdapter(buttonListAdapter);

class ButtonListAdapater  extends BaseAdapter
{
Context mContext;
private LayoutInflater mInflater;
List<"whatever you want to pass in such as images or textfiels or classes"> mDatas;

public ButtonListAdapater (Context context, List<"whatever you want to pass in such as images or textfiels or classes"> results)
{
mContext = context;
mDatas = results;
mInflater = LayoutInflater.from(mContext);
}

@Override
public int getCount()
{
return mDatas.size();
}

@Override
public Object getItem(int position)
{
return null;
}

@Override
public long getItemId(int position)
{
return 0;
}

@Override
public View getView(int position, View convertView, ViewGroup parent)
{
ViewHolder holder;

"whatever you want to pass in such as images or textfiels or classes" data = mDatas.get(position);

if (convertView == null) {
"whatever layout you made, on click effect can be in layout on in code"
convertView = mInflater.inflate(R.layout.data_list_item, null);

holder = new ViewHolder();

holder.tvButton = (TextView) convertView.findViewById(R.id.textViewButton);
holder.lbButton = (ImageButton) convertView.findViewById(R.id.Button);

convertView.setTag(holder);
} else {
holder = (ViewHolder) convertView.getTag();
}

holder.tvButton.setText(data.getData());

"With the button here it depends on what you want to do and how, since its perfectly fine to put an onclicklistener here or in the layout"
holder.llButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(context, OTherActivity.class);
startActivity(intent)
}
});


return convertView;
}

static class ViewHolder
{
TextView tvButton;
ImageButton lbButton;
}

data_list_item 布局 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="vertical" >
<ImageButton
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/R.id.Button/>

</LinearLayout>

关于Android ImageButton ListView ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32363086/

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