spinner不弹出列表

2014-07-14 12:31
条件:HTC t328w android 4.0.3
效果:无法上传图片
布局:
<?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" >
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content" >

         <TextView
             android:id="@+id/tvline"
             android:layout_width="wrap_content"
             android:layout_height="wrap_content"
             android:text="@string/tvNameLine"
             android:textColor="#000000" />
   
            <Spinner
                android:id="@+id/spTravel"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:prompt="@string/titleLine"
                android:textAppearance="?android:attr/textAppearanceMedium"
                android:textColor="#000000" />
        
    </LinearLayout>
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content" >

         <TextView
             android:id="@+id/tvtype"
             android:layout_width="wrap_content"
             android:layout_height="wrap_content"
             android:text="@string/tvCarType"
             android:textColor="#000000" />
   
            <Spinner
                android:id="@+id/spCarType"
                android:layout_width="match_parent"
                android:layout_height="wrap_content" />        
    </LinearLayout>
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal" >            

    <TextView
        android:id="@+id/car"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/tvNameCar"
        android:textColor="#000000" />

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal" >

    <EditText
        android:id="@+id/editCar"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:ems="10"
        android:hint="@string/hintCar"
        android:inputType="text"
        android:textColor="#000000" >

        <!-- <requestFocus />  -->
    </EditText>
</LinearLayout>
</LinearLayout>
</LinearLayout>
代码:
public class FillSpinner  extends Activity
{
public SQLiteDatabase tripDB;
public SDatabase objDB;
public Spinner spl;
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.tripcar);
spLine();
}
private void spLine()
{
try
{
objDB= new SDatabase();
if (tripDB==null)
{
tripDB=objDB.OpenDB(tripDB);
}
SimpleCursorAdapter adapterLine=null;
final View tripCar = LayoutInflater.from(getApplicationContext()).inflate(R.layout.tripcar,null);
spl=(Spinner)tripCar.findViewById(R.id.spTravel);
/* spl.setOnItemClickListener(new Spinner.OnItemClickListener(){
@Override
public OnClick()
{

}
}); */
if(tripDB == null)
return;
Cursor cur=tripDB.rawQuery("select ID as _id,Describe,Current from TripLine order by _id desc",null);

if( cur ==null)
General.Show(this, "游标为空",true);
else
General.Show(this, "数据库中旅程描述有"+Integer.toString(cur.getCount())+"行数据",true);

String[] from = new String[]{"Describe"};
int[] to = new int[]{android.R.id.text1};
adapterLine= new SimpleCursorAdapter(this,android.R.layout.simple_spinner_item,cur,from,to,1);
spl.setAdapter(adapterLine);
adapterLine.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);

spl.setSelection(0, false);
spl.setOnItemSelectedListener(new Spinner.OnItemSelectedListener() {     
@Override
            public void onItemSelected(AdapterView<?> parentView, View selectedItemView, int position, long id) 
            {
                // TODO Auto-generated method stub
             TextView v=(TextView)selectedItemView;
             v.setTextColor(color.black);
            
                int s1 = spl.getId();
                long s2 = spl.getItemIdAtPosition(position);
                String s3 = (String)spl.getItemAtPosition(position);
                General.Alert(FillSpinner.this, Integer.toString(s1)+"__"+Long.toString(s2)+"__"+s3);
            }
@Override
            public void onNothingSelected(AdapterView<?> arg0) 
            {
             // TODO Auto-generated method stub                       } 
            }
        }); 
int i=spl.getCount();
//String n=(String)spl.getItemAtPosition(1);
General.Show(this,"Spinner中有"+Integer.toString(i)+"项数据",false);
}
catch(Exception temp)
{
if(temp.getMessage().length()>0)
General.Alert(this, temp.getMessage());
}
}
}
问题:数据库有三条记录,cur有三项,spinner中有三项,不显示,点击后无下拉列表。才接触android,请高手提点!
对不起的是本人没有分了 

回复讨论(解决方案)

条件:HTC t328w android 4.0.3
效果:无法上传图片
布局:
<?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" >
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content" >

         <TextView
             android:id="@+id/tvline"
             android:layout_width="wrap_content"
             android:layout_height="wrap_content"
             android:text="@string/tvNameLine"
             android:textColor="#000000" />
   
            <Spinner
                android:id="@+id/spTravel"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:prompt="@string/titleLine"
                android:textAppearance="?android:attr/textAppearanceMedium"
                android:textColor="#000000" />
        
    </LinearLayout>
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content" >

         <TextView
             android:id="@+id/tvtype"
             android:layout_width="wrap_content"
             android:layout_height="wrap_content"
             android:text="@string/tvCarType"
             android:textColor="#000000" />
   
            <Spinner
                android:id="@+id/spCarType"
                android:layout_width="match_parent"
                android:layout_height="wrap_content" />        
    </LinearLayout>
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal" >            

    <TextView
        android:id="@+id/car"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/tvNameCar"
        android:textColor="#000000" />

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal" >

    <EditText
        android:id="@+id/editCar"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:ems="10"
        android:hint="@string/hintCar"
        android:inputType="text"
        android:textColor="#000000" >

        <!-- <requestFocus />  -->
    </EditText>
</LinearLayout>
</LinearLayout>
</LinearLayout>
代码:
public class FillSpinner  extends Activity
{
public SQLiteDatabase tripDB;
public SDatabase objDB;
public Spinner spl;
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.tripcar);
spLine();
}
private void spLine()
{
try
{
objDB= new SDatabase();
if (tripDB==null)
{
tripDB=objDB.OpenDB(tripDB);
}
SimpleCursorAdapter adapterLine=null;
final View tripCar = LayoutInflater.from(getApplicationContext()).inflate(R.layout.tripcar,null);
spl=(Spinner)tripCar.findViewById(R.id.spTravel);
/* spl.setOnItemClickListener(new Spinner.OnItemClickListener(){
@Override
public OnClick()
{

}
}); */
if(tripDB == null)
return;
Cursor cur=tripDB.rawQuery("select ID as _id,Describe,Current from TripLine order by _id desc",null);

if( cur ==null)
General.Show(this, "游标为空",true);
else
General.Show(this, "数据库中旅程描述有"+Integer.toString(cur.getCount())+"行数据",true);

String[] from = new String[]{"Describe"};
int[] to = new int[]{android.R.id.text1};
adapterLine= new SimpleCursorAdapter(this,android.R.layout.simple_spinner_item,cur,from,to,1);
spl.setAdapter(adapterLine);
adapterLine.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);

spl.setSelection(0, false);
spl.setOnItemSelectedListener(new Spinner.OnItemSelectedListener() {     
@Override
            public void onItemSelected(AdapterView<?> parentView, View selectedItemView, int position, long id) 
            {
                // TODO Auto-generated method stub
             TextView v=(TextView)selectedItemView;
             v.setTextColor(color.black);
            
                int s1 = spl.getId();
                long s2 = spl.getItemIdAtPosition(position);
                String s3 = (String)spl.getItemAtPosition(position);
                General.Alert(FillSpinner.this, Integer.toString(s1)+"__"+Long.toString(s2)+"__"+s3);
            }
@Override
            public void onNothingSelected(AdapterView<?> arg0) 
            {
             // TODO Auto-generated method stub                       } 
            }
        }); 
int i=spl.getCount();
//String n=(String)spl.getItemAtPosition(1);
General.Show(this,"Spinner中有"+Integer.toString(i)+"项数据",false);
}
catch(Exception temp)
{
if(temp.getMessage().length()>0)
General.Alert(this, temp.getMessage());
}
}
}
问题:数据库有三条记录,cur有三项,spinner中有三项,不显示,点击后无下拉列表。才接触android,请高手提点!
对不起的是本人没有分了 







                 Spinner spinner = (Spinner) findViewById(R.id.spinner);
		ArrayAdapter<String> aa = new ArrayAdapter<String>(this,
				android.R.layout.simple_spinner_item, items);
		aa.setDropDownViewResource(android.R.layout.simple_spinner_item);
		spinner.setAdapter(aa);
		spinner.setOnItemSelectedListener(new OnItemSelectedListener() {
			
			public void onItemSelected(AdapterView<?> parent, View view,
					int position, long id) {
				//selection.setText(items[position]);
				selection.setText(position+ "");

			}

			public void onNothingSelected(AdapterView<?> parent) {
				if(selection != null){
					int item = Integer.parseInt(selection.getText().toString().trim());
					spinner.setSelection(0, false);
					spinner.setSelection(item, true);
				}
			}

		});


诚请高手指点,我自己木辙了
补充一点:点击后就只Spinner的背景色变一下,其它都木有了
方法已发到你的邮箱里了,能解决就给分
楼主解决没?怎么解决地?