0
我似乎在向越來越應用程序崩潰:Android的崩潰使用setVisibility(View.VISIBLE)時
parent.findViewById(R.id.a_1).setVisibility(View.VISIBLE);
不知道什麼即時做錯了
代碼如下
layouttext.java
public class layouttest extends Activity {
private Spinner solvefor;
private ArrayAdapter<CharSequence> featuresAdapter;
private List<CharSequence> featuresList;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
featuresList = new ArrayList<CharSequence>();
featuresAdapter = new ArrayAdapter<CharSequence>(this, android.R.layout.simple_spinner_item, featuresList);
featuresAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
solvefor = ((Spinner) layouttest.this.findViewById(R.id.solvefor));
solvefor.setAdapter(featuresAdapter);
featuresAdapter.add("Velocity");
featuresAdapter.add("Time");
featuresAdapter.add("Distance");
solvefor.setOnItemSelectedListener(new MyOnItemSelectedListener());
}
}
MyOnItemSelectedListener.java 包android.example.layouttest;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemSelectedListener;
import android.widget.Toast;
public class MyOnItemSelectedListener implements OnItemSelectedListener {
private static final int SPINNER_OPTION_FIRST = 0;
private static final int SPINNER_OPTION_SECOND = 1;
public void onItemSelected(AdapterView<?> parent, View view, int pos, long id) {
switch(pos) {
case SPINNER_OPTION_FIRST: {
Toast.makeText(parent.getContext(), "0", Toast.LENGTH_LONG).show();
break;
}
case SPINNER_OPTION_SECOND: {
Toast.makeText(parent.getContext(), "1", Toast.LENGTH_LONG).show();
parent.findViewById(R.id.a_1).setVisibility(View.VISIBLE);
parent.findViewById(R.id.a_2).setVisibility(View.VISIBLE);
break;
}
}
}
public void onNothingSelected(AdapterView<?> parent) {
// Do nothing.
}
}
你確定它是'parent'你想要查找view而不是'view'嗎? – Falmarri 2010-11-15 23:57:23
您可以添加應用程序日誌和異常堆棧跟蹤。沒有他們,很難提供幫助。 – Juhani 2010-11-16 00:16:53