问题描述
在我的应用程序,我有活性基团,其中我有一个自定义的ListView用的ImageView,TextView中和微调。错误来当我点击微调。这里是code ..
In my application, i have activity group in which i have a custom ListView with ImageView, TextView and a spinner. Error comes when i click on the spinner. here is the code..
final ListView list = (ListView)findViewById(R.id.submenu_list);
MyCustomAdapter adapter = new MyCustomAdapter(this, mylist, 0, null, null);
list.setAdapter(adapter);
list.setTextFilterEnabled(true);
private class MyCustomAdapter extends SimpleAdapter {
public MyCustomAdapter(Context context,
List<? extends Map<String, ?>> data, int resource,
String[] from, int[] to) {
super(context, data, resource, from, to);
}
public View getView(final int position, View convertView, ViewGroup parent) {
if (convertView == null) {
convertView = getLayoutInflater().inflate(R.layout.submenu_items,
null);
}
((TextView) convertView.findViewById(R.id.food_name))
.setText(estimated[position]);
((TextView) convertView.findViewById(R.id.prize))
.setText("Price : "+price[position]);
((ImageView) convertView.findViewById(R.id.imageview))
.setImageResource(image[position]);
Spinner spinner = (Spinner) convertView.findViewById(R.id.spinner);
ArrayAdapter<CharSequence> sadapter = ArrayAdapter.createFromResource(getParent(), R.array.number, android.R.layout.simple_spinner_item);
sadapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
spinner.setAdapter(sadapter);
return convertView;
}
}
在我的活动组中另一个活动,我有微调简单的布局。为了产生微调,我有我的$ C $如下:C:
In my another activity inside activity group, i have simple layout with spinner. To generate the spinner i have my code as below:
public class FoodDetailPage extends Activity {
Spinner spinner;
Button back_button,my_order,add_order;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
View viewToLoad = LayoutInflater.from(this.getParent()).inflate(R.layout.food_details, null);
this.setContentView(viewToLoad);
back_button = (Button) findViewById(R.id.back_button);
add_order = (Button) findViewById(R.id.add_order);
back_button.setOnClickListener(new OnClickListener() {
public void onClick(View view) {
Intent intent =new Intent(FoodDetailPage.this,SubMenu.class);
startActivity(intent);
}
});
this.spinner =(Spinner) findViewById(R.id.spinner);
ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(this, R.array.number, R.layout.spinnerlayout);
adapter.setDropDownViewResource(R.layout.spinnerlayout);
spinner.setAdapter(adapter);
}
问题是与活动组,我的应用程序挂起放置在自定义的ListView一个微调的时候。
Problem is when placing a spinner in custom ListView with Activity group, my application hangs.
推荐答案
尝试通过 this.get preNT()
到 MyCustomAdapter
是这样的:
MyCustomAdapter adapter = new MyCustomAdapter(this.getPrent(), mylist, 0, null, null);
和做一个上下文变量在MyCustomAdapter
and make a Context variable in the MyCustomAdapter
private class MyCustomAdapter extends SimpleAdapter {
Context mContext;
public MyCustomAdapter(Context context,List<? extends Map<String, ?>> data, int resource, String[] from, int[] to)
{
super(context, data, resource, from, to);
mContext = context;
}
//getView implementation
}
和传递 mContext
到 ArrayAdapter
在 getView()
ArrayAdapter.createFromResource(mContext, R.array.number, android.R.layout.simple_spinner_item);
这篇关于与微调在自定义列表活动组内的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!