我似乎無法弄清楚如何做到這一點,基本上我有一個列表視圖,每個按鈕都有自己的值,這一切都很好,直到我想要隱藏某些按鈕,這一切都會發生。基於if語句隱藏動態添加的按鈕
此列表視圖都有它自己的自定義適配器該代碼是:空間刪除
進口,但它們的存在。
public class FriendsArrayAdapter extends ArrayAdapter<Friend>
{
public FriendsArrayAdapter
(Activity context, int resourceId, ArrayList<Friend> friends)
{
super(context, resourceId, friends);
this.context = context;
this.friends = friends;
this.resourceId = resourceId;
}
@Override
public View getView(int position, View convertView, ViewGroup parent)
{
View rowView = convertView;
if (rowView == null)
{
LayoutInflater vi = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
rowView = vi.inflate(resourceId, null);
}
alert = new AlertDialog.Builder(context);
alert.setTitle("Hanged! Online Play");
alert.setMessage("Enter a word for your opponent to guess. Alphabetical characters only and maximum of 25 characters long.");
final EditText input = new EditText(context);
alert.setView(input);
alert.setPositiveButton("Ok", new DialogInterface.OnClickListener()
{
public void onClick(DialogInterface dialog, int whichButton)
{
wordToGuess = input.getText().toString();
SubmitWord submitTask = new SubmitWord();
submitTask.execute(new String[] { "http://www.hanged.comli.com/main.php" });
Log.i("postData", wordToGuess);
}
});
alert.setNegativeButton("Cancel", new DialogInterface.OnClickListener()
{
public void onClick(DialogInterface dialog, int whichButton)
{
Intent intent = new Intent(context, NetPlay.class);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
context.startActivity(intent);
}
});
final Friend f = friends.get(position);
TextView rowTxt = (TextView) rowView.findViewById(R.id.rowtext_top);
rowTxt.setText(f.name+" ");
Button battleBtn = (Button) rowView.findViewById(R.id.battleBtn);
battleBtn.setText(f.id+" Accept Challenge");
battleBtn.setOnClickListener(new OnClickListener()
{
@Override
public void onClick(View v)
{
rivalid = f.id;
AcceptChallenge task2 = new AcceptChallenge();
task2.execute(new String[] { "http://www.hanged.comli.com/get-currentgame.php" });
}
});
Button newgameBtn = (Button) rowView.findViewById(R.id.newgameBtn);
newgameBtn.setText(f.id+" Start new game.");
newgameBtn.setOnClickListener(new OnClickListener()
{
@Override
public void onClick(View v)
{
rivalid = f.id;
alert.show();
}
});
for (int i = 0;i<NetPlay.victimArray.length-1;i++)
{
Log.i("VICTIM ARRAY DATA ", NetPlay.victimArray[i]);
if (NetPlay.victimArray[i].equals(NetPlay.myId))
{
ingame = false;
}
else
{
ingame = true;
}
}
for (int i = 0;i<NetPlay.rivalArray.length-1;i++)
{
Log.i("RIVAL ARRAY DATA ", NetPlay.rivalArray[i]);
if (NetPlay.rivalArray[i].equals(NetPlay.myId))
{
battle = true;
}
else
{
battle = false;
}
}
if (battle.equals(false))
{
battleBtn.setVisibility(View.INVISIBLE);
}
if (ingame.equals(false))
{
newgameBtn.setVisibility(View.INVISIBLE);
}
return rowView;
}
每當我設法隱藏這些按鈕,它們都得到隱藏的,而不僅僅是如果這是有道理的,應該被隱藏的按鈕? 這個視圖依賴於來自asynchtask的一些數據,如果這些信息有幫助的話。
真的很感謝這個幫助,完全令我困惑,我怎麼可能做到這一點。
這是在我的主要活動中調用listview的地方。
listView = (ListView) findViewById(R.id.friendsview);
friendsArrayAdapter = new FriendsArrayAdapter(this, R.layout.rowlayout, friends);
listView.setAdapter(friendsArrayAdapter);
每個ListView項有 'N' 按鈕。當您試圖隱藏其中一個按鈕時,所有'n'按鈕都將被隱藏。對??或所有listView項目的所有按鈕? – 2012-08-15 05:33:19
你是對的,但是它們是單獨的按鈕,因爲它們每個都有獨特的文本值,所以我認爲它們也是獨一無二的,不會被大量移除,按鈕將被添加到同一類中的listview中,以便它們被隱藏在,所以我不能找出他們的問題是什麼 – 2012-08-15 05:37:12
你應該**不**發佈您的整個源代碼。只有運行不正常的部分應該足夠了。 – JoxTraex 2012-08-15 05:45:23