這是函數,我想使用微調,從API獲取數據,但問題是,微調下拉不顯示。我是新的android.I附加下面的代碼。請提示我解決方案。代碼中沒有任何錯誤。我打印數組獲取數據。唯一的問題是下拉式不顯示。當我點擊按鈕響應得到。微調不顯示
@Override
public void onClick(View v)
{
String access=op.getUrl(getApplicationContext(),"ticket","update_properties","");
JSONArray access_denied = null;
try
{
access_denied = new editProperties(access).execute().get();
String access_result =access_denied.toString();
if(access_result.equals("[\"Accessdenied\"]"))
{
Operation.showToast(getApplicationContext(), R.string.access);
}
else
{
//Log.d("In the else Condition : ","Success");
String DEPT_URL=op.getUrl(getApplicationContext(),"ticket","get_department","&vis_all_department=1");
final String dept=tv_dept.getText().toString();
filter_dept_id=tv_dept_id.getText().toString();
if(v.getId()==R.id.td_tv_dept)
{
ArrayAdapter<String> dept_Adapter=op.get_dept_adapter(DEPT_URL,DEPARTMENT,Ticket_properties.this,domain_id);
final ArrayAdapter<String> dept_id_Adapter=op.get_dept_adapter(DEPT_URL,DEPARTMENT_ID,Ticket_properties.this,domain_id);
spin.setAdapter(dept_Adapter);
final int dept_Position = dept_Adapter.getPosition(dept);
spin.setSelection(dept_Position);//THIS ONE
spin.performClick();
spin.setOnItemSelectedListener(new OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> parent, View view,
int pos, long id) {
// TODO Auto-generated method stub
String selected_item=parent.getItemAtPosition(pos).toString();
String selected_item_id=dept_id_Adapter.getItem(pos).toString();
String filter="&vis_ticket_id="+Ticket_id+"&vis_action=department&vis_update_id="+selected_item_id;
String UPDATE_DEPT_URL=op.getUrl(getApplicationContext(),"ticket","update_properties",filter);
JSONArray dept_array;
try
{
dept_array = new editProperties(UPDATE_DEPT_URL).execute().get();
String result =dept_array.toString();
if(result.equals("[\"success\"]"))
{
tv_dept.setText(selected_item);
tv_dept_id.setText(selected_item_id);
}
else {Operation.showToast(getApplicationContext(), R.string.error);}
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (ExecutionException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
@Override
public void onNothingSelected(AdapterView<?> arg0) {
// TODO Auto-generated method stub
spin.setSelection(dept_Position);
}
});
}
else if
{
//NEXT CODE
}
// ***************************************** *****************************
public ArrayAdapter<String> get_dept_adapter(String URL, String ITEM, Activity context,String domain_id)
{
// TODO Auto-generated method stub
JSONArray array ;
List<String> item_list = new ArrayList<String>();
try {
array=new adapter(URL+"&vis_encode=json",context).execute().get();
for (int i = 0; i <array.length(); i++)
{
JSONObject object;
try {
object = array.getJSONObject(i);
String new_domain_id=object.getString("domain_id");
if(domain_id.equals(new_domain_id))
{
String item=object.getString(ITEM);
item_list.add(item);
}
} catch (JSONException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
}
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (ExecutionException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
ArrayAdapter<String> item_Adapter = new ArrayAdapter<String>(context, android.R.layout.simple_spinner_item,item_list);
item_Adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
return item_Adapter;
}
// ************ *******************************
Hello i just added the android:spinnerMode="dialog"
style="@android:style/Widget.Spinner.DropDown" these two lines and working fine.
Previous
==========
<Spinner
android:id="@+id/td_spin"
android:layout_width="0dp"
android:layout_height="0dp" />
After
=======
<Spinner
android:id="@+id/td_spin"
android:layout_width="0dp"
android:layout_height="0dp"
android:spinnerMode="dialog"
style="@android:style/Widget.Spinner.DropDown"
/>
你爲什麼叫'spin.performClick(); ' –
@ kamran:它的前面的代碼我只是解決了bug。但是當我評論spin.performClick()............輸出沒有得到。 –
很好..用解決方案更新你的問題 –