我有一个ListActivity,其数组适配器声明为像arrayAdapter = new ArrayAdapter<String> (this, android.R.layout.simple_list_item_checked);这样在最右边显示了一堆带有复选标记的行.你能告诉我如何获得这些复选标记的引用或如何检查/取消选中它们吗?
我在布局中有Listviews,我希望用户知道有更多的单元格要查看和滚动.列表视图默认情况下没有可见的滚动条.
我得到的一个建议是从它的末尾开始显示列表,然后自动向上滚动到顶部.这将向用户显示有滚动的内容.
如何在Android上完成?
如何使用我的新阵列更新ArrayAdapter?
Belwo是我的ArrayAdapter,添加了一个默认数组.
String[] array_spinner = new String[]{"Select your state."};
ArrayAdapter<String> adapter = new ArrayAdapter<String> (this,android.R.layout.simple_spinner_item,array_spinner);
adapter.setDropDownViewResource(R.layout.state_spinner_layout);
Myspinner.setAdapter(adapter);
Run Code Online (Sandbox Code Playgroud)
现在我加载一些JSON数据来解析信息array_spinner_data,我想调用notifyDataSetChanged()
array_spinner = new String[]jsonArray.length();
for (int i=0; i<jsonArray.length(); i++)
{
String styleValue = jsonArray.getJSONArray(i).getString(0);
Log.d(TAG, styleValue);
array_spinner[i] = styleValue;
}
Log.d(TAG, String.valueOf(array_spinner.length));
adapter.notifyDataSetChanged();
Run Code Online (Sandbox Code Playgroud)
我没有看到任何错误,我的所有Log.d都应该回来了.但是当我点击我的微调器时,所有显示的都是原始的,Select your state 我遗漏了一些基本的onCreate和Json加载的东西,但如果有人需要看到它只是让我知道.
在我的ArrayAdapter类中,我捕获传入的上下文.然后在getView方法中,我有这个if语句:
if(m.getSide() == RED) {
v.setBackgroundColor(lc.getResources().getColor(R.color.red_bouy));
Log.d("MA", "HERE");
} else if(m.getSide() == BLACK) {
v.setBackgroundColor(lc.getResources().getColor(R.color.black_bouy));
}
Run Code Online (Sandbox Code Playgroud)
(lc是我从构造函数中获取的上下文)
如果我只使用Color.red,它可以找到.我见过的所有例子都使用ghet getResources ...,但是来自一个活动.
有什么建议?
我正在开发一个Android 3.1应用程序.
我有自定义ArrayAdapter.我想在ListView中显示名称列表.
这些名称是可以下载并在本地保存的表单.当用户下载并保存一个或多个时,我打电话updateFormsNotDownloaded().但是当我这样做时,我得到一个IndexOutOfBoundsException.我认为这个问题是因为我打电话notifyDataSetChanged().
看看我的代码:
public class FormAdapter extends ArrayAdapter<Form>
{
private Context context;
private int layoutResourceId;
private List<Form> forms;
private ArrayList<Integer> checkedItemsPosition;
private Button downloadButton;
public ArrayList<Integer> getCheckedItemsPosition()
{
return checkedItemsPosition;
}
public String[] getSelectedFormsId()
{
String[] ids = new String[checkedItemsPosition.size()];
int i = 0;
for(Integer pos : checkedItemsPosition)
{
Form f = forms.get(pos.intValue());
ids[i] = f.FormId;
i++;
}
return ids;
}
/**
* Called when selected forms has been downloaded and save it locally …Run Code Online (Sandbox Code Playgroud) 我搜索了与此问题相关的现有教程,我按照这个例子.但我仍然得到同样的错误.当我更改android.R.layout.simple_list_item1行时,它将无法正常工作.
mycode的:
public class Lisearch extends Activity {
private ListView lv;
private EditText et;
private String listview_array[] = { "ONE", "TWO", "THREE", "FOUR", "FIVE",
"SIX", "SEVEN", "EIGHT", "NINE", "TEN" };
private ArrayList<String> array_sort= new ArrayList<String>();
int textlength=0;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_lisearch);
//TextView tv=(TextView)findViewById(R.id.text);
lv = (ListView) findViewById(R.id.ListView01);
et = (EditText) findViewById(R.id.EditText01);
//lv.setAdapter(new ArrayAdapter<String>(this,
//R.layout.activity_lisearch, listview_array));
et.addTextChangedListener(new TextWatcher()
{
public void afterTextChanged(Editable s)
{
// Abstract Method of TextWatcher Interface.
}
public void beforeTextChanged(CharSequence s,
int start, …Run Code Online (Sandbox Code Playgroud) 我想创建一个下拉颜色选择器,像这样(抱歉丑陋的图像):

我只需要一些颜色(让我们说6)所以我不需要一个完整的颜色选择器,下拉列表将正常工作.
我知道我必须为Spinner扩展数组适配器并覆盖getDropDownView和getView.
我不知道的是如何创建一个带边框和纯色背景的方框.
我知道我可以在drawable中定义自己的形状.无论如何,我必须在运行时设置背景颜色,所以我还需要更改视图并设置正确的背景颜色.
这是最好的方法吗?谢谢.
我遇到了以下问题.我有一个listview和两个按钮.在片段的开头,一些数据存储在2个Arraylists中.首先,第一个Arraylist的内容显示在listview中,工作正常.当用户单击第一个按钮时,ListView会显示第二个ArrayList.这对用户来说很好,但只要我调用adapter.clear().第一个Arraylist被删除了.因此,他无法通过单击第一个按钮切换回第一个列表.我从不删除Arraylist,所以我想知道为什么adapter.clear()会这样做.你能帮忙的话,我会很高兴.代码在下面.
public class MessagesFragment extends Fragment {
private ArrayList<Message> outbound;
private ArrayList<Message> inbound;
private MessageAdapter messageadapter;
private int box;
private View rootView;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.fragment_messages, container,
false);
outbound = new ArrayList<Message>();
inbound = new ArrayList<Message>();
this.rootView = rootView;
box = 0;
messageadapter = new MessageAdapter(getActivity(),
R.layout.item_message, inbound);
((ListView) rootView.findViewById(R.id.lv_message))
.setAdapter(messageadapter);
initializeListeners();
return rootView;
}
private void initializeListeners() {
rootView.findViewById(R.id.rb_message_inbox).setOnClickListener(
new OnClickListener() {
@Override
public void onClick(View v) {
showBox(0); …Run Code Online (Sandbox Code Playgroud) 好吧标题说明了一切.我不确定为什么它不想工作.
这是在AsyncWorker中,因此可能是问题.变量也在受保护的方法之外,但在内部时也是如此.
private class MyAsyncTask extends AsyncTask<String, String, String> {
ListView workersList = (ListView)findViewById (R.id.workers_list);
ArrayList<String> itemsList = new ArrayList<String>();
protected String doInBackground(String... arg0) {
Run Code Online (Sandbox Code Playgroud)
然后是
ArrayAdapter<String> adapter = new ArrayAdapter<String>(android.R.layout.simple_list_item_1, itemsList);
Run Code Online (Sandbox Code Playgroud) 我有一个由ArrayAdapter填充的listView.我想要ListView的第一个Row/Cell的不同布局.
另外我发现了一个非常相似的问题,但cldnt在我的代码中添加了headerView,不同的行布局仅用于BaseAdapter中的第一行
我使用下面的代码实现了它:
public class ActorAdapter extends ArrayAdapter<Actors> {
ArrayList<Actors> actorList;
LayoutInflater vi;
int Resource1;
int Resource2;
ViewHolder holder;
public ActorAdapter(Context context, int resource, ArrayList<Actors> objects) {
super(context, resource, objects);
vi = (LayoutInflater) context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
Resource1 = resource;
Resource2 = resource;
actorList = objects;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
View v = convertView;
if (v == null) {
holder = new ViewHolder();
if (position == 0){
v = vi.inflate(R.layout.first_item, null);
holder.imageview = (ImageView) …Run Code Online (Sandbox Code Playgroud) android android-arrayadapter android-layout android-listview
android ×10
listview ×2
arraylist ×1
arrays ×1
checkmark ×1
color-picker ×1
java ×1
listactivity ×1
scroll ×1