-2
我想單擊微調框和下一頁來顯示android studio中繪圖的圖像。通過單擊微調框來顯示圖像
這顯示了微調僅
public class navigation extends AppCompatActivity implements AdapterView.OnItemSelectedListener {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_navigation);
Spinner end = (Spinner) findViewById(R.id.end_spinner);
//Create an ArrayAdapter using the string array and a default spinner layout
ArrayAdapter<CharSequence> end_adapter = ArrayAdapter.createFromResource(this, R.array.end_point, android.R.layout.simple_spinner_item);
//Specify the layout to use when the list of choices appears
end_adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
//Apply the adapter to the spinner
end.setAdapter(end_adapter);
end.setOnItemSelectedListener(this);
}
@Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
if (parent.getId() == R.id.end_spinner){
if(position >=1 && position <=16){
TextView mytext = (TextView) view;
Toast.makeText(this,mytext.getText()+" selected",Toast.LENGTH_LONG).show();
Intent PlanIntent = new Intent(navigation.this, AStar.class);
Bundle bundle = new Bundle();
bundle.putInt("classname",position);
PlanIntent.putExtras(bundle);
startActivity(PlanIntent);
}
else {
Toast.makeText(this,"Please select the destination",Toast.LENGTH_LONG).show();
}
}
}
public void onNothingSelected(AdapterView<?> parent)
{
Spinner start = (Spinner) findViewById(end_spinner);
assert start != null;
start.setOnItemSelectedListener(this);
if (start.getId() != end_spinner) {
}
}
@Override
public void onBackPressed(){
startActivity(new Intent(this,MainActivity.class));
finish();
}
}
這是下一個頁面,可以顯示圖像
公共類愛仕達擴展AppCompatActivity {
ImageView imageView;
PhotoViewAttacher mAttacher;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_astar);
imageView = (ImageView) findViewById(R.id.imageView);
int position = getIntent().getIntExtra("classname", -1);
if(position != -1){
int classImg = classImages[position];
imageView.setImageResource(classImg);
}
mAttacher = new PhotoViewAttacher(imageView);
}
}
我在16類名微調,我想要做的是,當用戶點擊每個類名稱時,它將顯示一張可繪製的圖片。每個班級名稱都有不同的圖像。我的想法是使用,但我不知道代碼。
雅。 if(bundle!= null){ }這裏我不知道如何編寫if else代碼 –
你別別的語句......不知道你爲什麼認爲你做 –
以int classPosition = bundle.getInt' –