gpt4 book ai didi

android - android 2.3.3 及更高版本中微调器的下拉模式

转载 作者:太空狗 更新时间:2023-10-29 15:27:09 24 4
gpt4 key购买 nike

大家好!我查看了有关此主题的其他问题,但没有找到全面的答案。所以,我再问一次。我的应用程序必须在 android 2.3.3 及更高版本上运行。我有一个微调器和适配器,用于通过它显示数据。当用户点击微调器时,我想以下拉方式显示数据列表。我真的不明白我应该如何实现这一目标。

@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
_messageSpinner = (Spinner) findViewById(R.id.message_filter_spnStatus);

ArrayList<String> messageStatuses = new ArrayList<String>();
messageStatuses.add("All");
messageStatuses.add("Unread");
messageStatuses.add("Read");

_messageSpinner.setAdapter(new MessageStatusAdapter(messageStatuses));
}

public class MessageStatusAdapter implements SpinnerAdapter
{
ArrayList<String> mMessageStatuses = new ArrayList<String>();
LayoutInflater layoutInflater = getLayoutInflater();

public MessageStatusAdapter(ArrayList<String> messageStatuses)
{
mMessageStatuses = messageStatuses;
}

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

@Override
public Object getItem(int arg0)
{
// TODO Auto-generated method stub
return null;
}

@Override
public long getItemId(int arg0)
{
// TODO Auto-generated method stub
return 0;
}

@Override
public int getItemViewType(int arg0)
{
// TODO Auto-generated method stub
return 0;
}

@Override
public View getView(int position, View convertView, ViewGroup parent) {
final TextView filterName;

if (convertView == null) {
filterName = (TextView) layoutInflater.inflate(R.layout.item_spinner_message_status, parent, false);
} else {
filterName = (TextView) convertView;
}

filterName.setText("StatusTest");
return filterName;
}

@Override
public int getViewTypeCount()
{
// TODO Auto-generated method stub
return 0;
}

@Override
public boolean hasStableIds()
{
// TODO Auto-generated method stub
return false;
}

@Override
public boolean isEmpty()
{
// TODO Auto-generated method stub
return false;
}

@Override
public void registerDataSetObserver(DataSetObserver arg0)
{
// TODO Auto-generated method stub

}

@Override
public void unregisterDataSetObserver(DataSetObserver arg0)
{
// TODO Auto-generated method stub

}

@Override
public View getDropDownView(int position, View convertView, ViewGroup parent) {
final TextView filterName;
if (convertView == null) {
filterName = (TextView) layoutInflater.inflate(R.layout.item_spinner_message_status_dropdown, parent, false);
//filterName.setEllipsize(TruncateAt.END);
} else {
filterName = (TextView) convertView;
}

filterName.setText("DropDownItem");
return filterName;
}

}

item_spinner_message_status:

<?xml version="1.0" encoding="utf-8"?>
<TextView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textSize="10pt"
android:textColor="@color/text_gray" >
</TextView>

item_spinner_message_status_dropdown:

<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/tvMessageStatusDropdown"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textSize="10pt"
android:textColor="@color/text_gray"
android:height="50dp"
android:gravity="center_vertical"
android:padding="2dp" >
</TextView>

最佳答案

_messageSpinner = (Spinner) findViewById(R.id.message_filter_spnStatus);
String[] messageStatuses = { "All", "Unread", "Read" };
ArrayAdapter<String> dataAdapter = new ArrayAdapter<String>(context, android.R.layout.simple_spinner_item, messageStatuses);
dataAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
_messageSpinner.setAdapter(dataAdapter);

在您的 onCreate()

中尝试此代码 fragment

关于android - android 2.3.3 及更高版本中微调器的下拉模式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17472205/

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