gpt4 book ai didi

android - 如何将字符串分解为微调器和编辑文本值?

转载 作者:行者123 更新时间:2023-11-30 01:29:15 25 4
gpt4 key购买 nike

我创建了一个定义 STD(地区)代码的微调器和一个定义电话号码的编辑文本。

 <LinearLayout
android:layout_width="wrap_content"
android:layout_height="@dimen/fup_ll_height"
android:orientation="horizontal"
android:layout_marginTop="@dimen/fup_ll_margintop">
<Spinner
android:id="@+id/phone1_spinner"
android:layout_width="@dimen/fup_spinner_width"
android:layout_height="@dimen/fup_spinner_height"
android:background="@drawable/spinner_phone"
android:gravity="center"
android:spinnerMode="dropdown"
android:layout_marginTop="@dimen/fup_spinner_margintop"
android:layout_marginRight="@dimen/fup_spinner_marginright"
/>

<EditText
android:id="@+id/Phone1EditText"
android:layout_width="fill_parent"
android:layout_height="@dimen/fup_edittext_phone1_height"
android:background="@drawable/input_box"
android:gravity="center_vertical"
android:hint="Phone1"
android:inputType="phone"
android:layout_marginTop="@dimen/fup_edittext_margintop"
android:paddingLeft="@dimen/fup_edittext_phone2_paddingleft"
android:singleLine="true"
android:textSize="@dimen/fup_commontextview_textsize" />
</LinearLayout>

来自服务器的包含区号的电话号码是 9 位或 10 位数字。其中编辑文本(电话号码)必须包含 7(七)个数字。

在编程中我如何检查区号是两位数还是三位数?

我的编码是:-

private String[] areaCodes;
private String phone1;
private ArrayAdapter<String> adapter;
private Spinner phone1Spinner

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
phone1Spinner = (Spinner) view.findViewById(R.id.phone1_spinner);
Phone1EditText = (EditText) view.findViewById(R.id.Phone1EditText);

areaCodes = new String[]{"02", "03", "04", "08", "09", "050", "052", "054", "072", "073", "074", "077"};
adapter = new ArrayAdapter<String>(context, R.layout.list_spinner_phone, areaCodes);
adapter.setDropDownViewResource(R.layout.list_spinner_phone);
phone1Spinner.setAdapter(adapter);
phone1Spinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
phone1 = parent.getItemAtPosition(position).toString();
}

@Override
public void onNothingSelected(AdapterView<?> parent) {

}
});
//when i send data to server..its ok for me
phone1 = phone1 + Phone1EditText.getText().toString();
//but when retrieve data from server what should i do as data is in combined form means(areacode+phone number), either in 9 or 10 digits????

}

我已经试过了,但没有得到解决方案。

if (userProfileDataModel1.getUser().getPhone1().toString().length() == 9) {
if (!(userProfileDataModel1.getUser().getPhone1().substring(1, 2).equals(null))) {
int spinnerPosition = adapter.getPosition(userProfileDataModel1.getUser().getPhone1().substring(1, 3));
phone1Spinner.setSelection(spinnerPosition);
}

Phone1EditText.setText(userProfileDataModel1.getUser().getPhone1().substring(2, 9));
} else {
if (!(userProfileDataModel1.getUser().getPhone1().substring(0, 3).equals(null))) {
int spinnerPosition = adapter.getPosition(userProfileDataModel1.getUser().getPhone1().substring(0, 3));
phone1Spinner.setSelection(spinnerPosition);
}
Phone1EditText.setText(userProfileDataModel1.getUser().getPhone1().substring(3, 10));
}
}

最佳答案

您应该为此尝试这些代码行:-

String phone1;
YOUR_SPINNER.setOnItemSelectedListener(new OnItemSelectedListener()
{
@Override
public void onItemSelected(AdapterView adapter, View v, int i, long lng) {

phone1 = parent.getItemAtPosition(i).toString();

///AND THAN AFTER FIND THE LENGTH OF THE SELECTED TEXT

int length= phone1.length();



}
@Override
public void onNothingSelected(AdapterView<?> parentView)
{

}
});

关于android - 如何将字符串分解为微调器和编辑文本值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35984418/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com