我设计了一个列表视图,它有一个图像视图、文本视图和按钮。最初,imageview 和 textview 将在单击 imageview 时可见,删除按钮将对所选视图可见,但我的问题是在选择下一个列表选项时,我需要隐藏按钮,一次只需要显示一个按钮。谁能帮帮我?
public class HistoryMenu extends MainActivity {
public final static String ITEM_TITLE = "title";
public final static String ITEM_CAPTION = "caption";
public static Boolean deletedispflag=false;
public static View selectdelete=null;
String optionSelectedValue;
ArrayList<String> listString;
ArrayAdapter<String> aa;
ListView settingsSubList;
LayoutInflater linf;
// public String[] stringList={"N @ 17.3 MPH (16-18)","10:25, 20 June 2013","N @ 17.3 MPH (16-18)","10:25, 20 June 2013","N @ 17.3 MPH (16-18)","10:25, 20 June 2013","N @ 17.3 MPH (16-18)","10:25, 20 June 2013"};
// HistoryListAdapters historyListAdapter;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_history_menu);
settingsSubList = (ListView) findViewById(R.id.settings_sub_list);
LayoutParams layout = new LayoutParams(Gravity.CENTER);
LayoutInflater inflator = (LayoutInflater)this.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View v = inflator.inflate(R.layout.centered_menu_title, null);
((TextView)v.findViewById(R.id.title)).setTextColor(getResources().getColor(R.color.white));
this.getSupportActionBar().setCustomView(v,layout);
listString=new ArrayList<String>();
listString.add("history object 1");
listString.add("history object 2");
listString.add("history object 3");
listString.add("history object 4");
listString.add("history object 5");
MyArrayAdapter adapter = new MyArrayAdapter(this, R.layout.history_option_selector, listString);
settingsSubList.setAdapter(adapter);
settingsSubList.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View arg1, int position,
long arg3) {
}
});
}
public class MyArrayAdapter extends ArrayAdapter<String> {
int previousDegrees = 0;
int degrees = 90;
RotateAnimation animation = new RotateAnimation(0f, 90f, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f); //, 200, 200); // canvas.getWidth() / 2, canvas.getHeight() / 2);
Context context;
int layoutResourceId;
ArrayList<String> historyitems = new ArrayList<String>();
public MyArrayAdapter(Context context, int layoutResourceId,ArrayList<String> historyitems)
{
super(context, layoutResourceId, historyitems);
this.layoutResourceId = layoutResourceId;
this.context = context;
this.historyitems = historyitems;
}
@Override
public View getView(int position, View convertView, ViewGroup parent)
{
animation.setDuration(1000L);
View item = convertView;
if (item == null) {
LayoutInflater inflater = ((Activity) context).getLayoutInflater();
item = inflater.inflate(layoutResourceId, parent, false);
}
TextView items = (TextView) item.findViewById(R.id.history_list_option_text);
final ImageView select_option = (ImageView) item.findViewById(R.id.history_list_option_select_image);
final Button delete = (Button) item.findViewById(R.id.history_list_option_delete_button);
delete.setVisibility(View.INVISIBLE);
String itemtext = historyitems.get(position);
items.setText(itemtext);
select_option.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
select_option.startAnimation(animation);
if(deletedispflag == false)
{
delete.setVisibility(v.VISIBLE);
selectdelete = v;
deletedispflag=true;
}
else if(deletedispflag==true)
{
delete.setVisibility(selectdelete.INVISIBLE);
deletedispflag=false;
}
Toast.makeText(context, "Edit", Toast.LENGTH_LONG).show();
}
});
delete.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
Toast.makeText(context, "Delete", Toast.LENGTH_LONG).show();
}
});
return item;
}
}
@Override
public void onBackPressed() {
// TODO Auto-generated method stub
Intent intent = new Intent(this, MainActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(intent);
overridePendingTransition(R.drawable.activity_in_left_to_right_animation,R.drawable.activity_out_right_to_left_animation);
}
}