所以我在gridview中有圖像。這些圖像顯示在一個活動中。點擊其中一個圖像時,該圖像將啓動新的活動。在此活動中,如果用戶輸入正確答案,則開始新活動,表明答案正確。在用戶輸入正確答案之後,我想用gridwiew中的複選標記將此圖像設置得更加透明。如果用戶再次點擊這個正確的視圖,我想顯示相同的活動,表明它解決了正確的。我怎樣才能做到這一點?在gridview中設置圖像爲透明
這裏是我的活動包含網格視圖:
public class LogoSelectionActivity extends Activity {
.
.
gridview.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View v, int position, long id) {
Intent intent = new Intent(LogoSelectionActivity.this, LogoActivity.class);
intent.putExtra ("clicked_position", position);
startActivity(intent);
}
這裏是我的活動,其中用戶進行輸入:
public class LogoActivity extends Activity{
EditText text;
Button check;
Boolean a;
int id;
Names name;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_logo);
check = (Button) findViewById(R.id.Check_button);
text = (EditText) findViewById(R.id.editText1);
ImageView view = (ImageView)findViewById(R.id.imageView1);
final ImageView incorrect = (ImageView)findViewById(R.id.incorrect);
switch (getIntent().getIntExtra ("clicked_position", -1))
{
case 0:
view.setImageResource(R.drawable.adese);
id = R.drawable.adese;
break;
case 1:
view.setImageResource(R.drawable.birvar);
id = R.drawable.birvar;
break;
case 2:
view.setImageResource(R.drawable.agaoglu);
break;
case 3:
view.setImageResource(R.drawable.akinsoft);
break;
default:
view.setImageResource(R.drawable.afra);
id = R.drawable.afra;
}
name = Names.forDrawable(id);
check.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
a=name.isCorrect(text.getText().toString());
if(a==true){
Intent intent = new Intent(LogoActivity.this, CorrectActivity.class);
startActivity(intent);
}
else{
incorrect.setVisibility(0);
incorrect.setVisibility(4);
}
}
});
}
}
我希望我能清楚地解釋我的意圖。
它似乎工作。我嘗試了一個小例子。如果我在構造整個代碼時遇到問題,我會再次問你是否可以。感謝您的時間。 – ocry 2013-03-03 12:52:42
如果我點擊了已回答的視圖,我會得到表明該信息正確的活動。它工作正常。但是,如果我關閉該應用程序並重新打開它,則所有這些應用程序都會重置並以默認值開始。我怎樣才能做到永久? – ocry 2013-03-03 13:03:10
ohh爲此你必須選擇(1)共享首選項和(2)保存在數據庫中。 – 2013-03-04 03:43:19