使用 ActionSheet 中的选项更改按钮文本
Using options in ActionSheet to change Button text
我正在尝试在 android 中开发一个 UI 操作表。使用依赖项:
compile 'com.baoyz.actionsheet:library:1.1.6'
我在 android 中开发了一个操作表,如下所示:
ActionSheet in Android
每当从 actionSheet 中选择任何选项时,我都试图更改按钮文本。下面 javafile 中的 index 包含字符串位置,就像数组一样,但我无法从 index.[=14= 中获取字符串值]
这是我的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);
}
}
}
为什么不使用变量来存储这些值。
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]);
}
}
我正在尝试在 android 中开发一个 UI 操作表。使用依赖项:
compile 'com.baoyz.actionsheet:library:1.1.6'
我在 android 中开发了一个操作表,如下所示: ActionSheet in Android
每当从 actionSheet 中选择任何选项时,我都试图更改按钮文本。下面 javafile 中的 index 包含字符串位置,就像数组一样,但我无法从 index.[=14= 中获取字符串值]
这是我的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);
}
}
}
为什么不使用变量来存储这些值。
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]);
}
}