我正在尝试在android中开发一个UI动作表。使用依赖:
compile 'com.baoyz.actionsheet:library:1.1.6'
我在android中开发了一个动作表,如下所示: ActionSheet in Android
每当从actionSheet中选择任何选项时,我都会尝试更改按钮文本。下面的javafile中的索引包含与数组一样的字符串位置,但我无法从索引中获取字符串值。
这是我的javafile
:
public class billBookInfo extends AppCompatActivity implements ActionSheet.ActionSheetListener{
private Button change;
private String setValue;
private Button vtype;
private Button zone;
Button next;
Button previous;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_bill_book_info);
getSupportActionBar().hide();
vtype = (Button) findViewById(R.id.info_billbook_bt_vtype);
zone = (Button)findViewById(R.id.info_billbook_bt_zone);
}
}
public void onClick(View v){
switch (v.getId()) {
case R.id.info_billbook_bt_vtype:
setTheme(R.style.ActionSheetStyleiOS7);
change = vtype;
showActionSheet1();
break;
case R.id.info_billbook_bt_zone:
setTheme(R.style.ActionSheetStyleiOS7);
showActionSheet2();
change = zone;
break;
}
}
private void showActionSheet1() {
ActionSheet.createBuilder(this,getSupportFragmentManager())
.setCancelButtonTitle("Cancel")
.setOtherButtonTitles("Motorcycle","Scooter","Car","Van")
.setCancelableOnTouchOutside(true).setListener(this).show();
}
private void showActionSheet2() {
ActionSheet.createBuilder(this,getSupportFragmentManager())
.setCancelButtonTitle("Cancel")
.setOtherButtonTitles("Me", "Ko", "Sa", "Ja")
.setCancelableOnTouchOutside(true).setListener(this).show();
}
@Override
public void onDismiss(ActionSheet actionSheet, boolean isCancel) {
}
@Override
public void onOtherButtonClick(ActionSheet actionSheet, int index) {
int i = 0;
if ( i == index){
setValue = "".concat(getString(index));
change.setText(setValue);
}
}
}
答案 0 :(得分:1)
为什么不使用变量来存储这些值。
String vArr[] = new String[]{"Motorcycle","Scooter","Car","Van"};
String dArr[] = new String[]{"Me", "Ko", "Sa", "Ja"};
ActionSheet vSheet, dSheet;
private void showActionSheet1() {
vSheet = ActionSheet.createBuilder(this,getSupportFragmentManager())
.setCancelButtonTitle("Cancel")
.setOtherButtonTitles(vArr[0],vArr[1],vArr[2],vArr[3])
.setCancelableOnTouchOutside(true).setListener(this).show();
}
private void showActionSheet2() {
dSheet = ActionSheet.createBuilder(this,getSupportFragmentManager())
.setCancelButtonTitle("Cancel")
.setOtherButtonTitles(dArr[0],dArr[1],dArr[2],dArr[3])
.setCancelableOnTouchOutside(true).setListener(this).show();
}
@Override
public void onDismiss(ActionSheet actionSheet, boolean isCancel) {
}
@Override
public void onOtherButtonClick(ActionSheet actionSheet, int index) {
if ( actionSheet == vSheet){
change.setText(vArr[index]);
}
else{
change.setText(dArr[index]);
}
}