2016-09-17 40 views
-1

私のアプリケーションでテストした後、数値(電話)と文字列値(名前)がTextViewフィールドに表示されます。私はすべての非数値を削除したい。 @PrateekRathoreのフィードバックをtextView以外の数値をすべて削除する

public class SendingSMSActivity extends Activity{ 
private int mCount; 
private AutoCompleteTextView actv; 
private ArrayList<String> mcurrentssFistLastName_PhoneList = null; 
AutoCompleteTextView PhoneNumberAutoComp; 
MultiAutoCompleteTextView PhoneNumberMultiAutoComp; 

@Override 
protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.sending_sms_activity); 
    PhoneNumberAutoComp=(AutoCompleteTextView)findViewById(R.id.aCT_phone_number); 
    PhoneNumberMultiAutoComp=(MultiAutoCompleteTextView)findViewById(R.id.multiCompTextView); 

    ArrayAdapter adapter = new ArrayAdapter(this,android.R.layout.simple_list_item_1,init()); 

    PhoneNumberAutoComp.setAdapter(adapter); 
    PhoneNumberAutoComp.setThreshold(1); 

    PhoneNumberMultiAutoComp.setAdapter(adapter); 
    PhoneNumberMultiAutoComp.setTokenizer(new MultiAutoCompleteTextView.CommaTokenizer()); 
} 

private ArrayList<String> init(){ 
    mcurrentssFistLastName_PhoneList = new ArrayList<String>(); 
    //mcurrentssFistLastNameList = new ArrayList<String>(); 
    InnerDB db = new InnerDB(SendingSMSActivity.this); 

    final ArrayList<String> sPhoneList = db.getAllPhoneNumber(); 
    final ArrayList<String> sFirstLastNameList = db.getAllSFirstName(); 
    mCount = sPhoneList.size(); 
    for(int i = 0; i < mCount; i ++){ 
     mcurrentssFistLastName_PhoneList.add(sFirstLastNameList.get(i) +" " +sPhoneList.get(i)); 
     //mcurrentssFistLastNameList.add(sFirstLastNameList.get(i)); 
    } 

    return mcurrentssFistLastName_PhoneList; 
} 
@Override 
public boolean onCreateOptionsMenu(Menu menu) { 
    getMenuInflater().inflate(R.menu.menu_main, menu); 
    return true; 
} 

@Override 
public boolean onOptionsItemSelected(MenuItem item) { 
    // Handle action bar item clicks here. The action bar will 
    // automatically handle clicks on the Home/Up button, so long 
    // as you specify a parent activity in AndroidManifest.xml. 
    int id = item.getItemId(); 

    return super.onOptionsItemSelected(item); 
} 

@Override 
protected void onResume() { 
    super.onResume(); 
} 
} 
+0

あなたのXMLを投稿してください –

+0

あなたはいつでもreplaceAll( "[^ 0-9]"、 "");と置き換えることができます。これはあなたに数値だけを返します –

+0

ありがとう@PrateekRathore:String phonevalue = PhoneNumberAutoComp.getText()。toString(); String phoneNum = phonevalue.replaceAll( "[^ 0-9]"、 ""); PhoneNumberAutoComp.setText(phoneNum); –

答えて

0

あなたはいつもでReplaceAllに置き換えることができます( "[^ 0-9]"、 "");これは数値のみを返します。

1

は私が解決策だ:

String phonevalue = PhoneNumberAutoComp.getText().toString(); 
      String phoneNum =phonevalue.replaceAll("[^0-9]",""); 
      PhoneNumberAutoComp.setText(phoneNum); 
関連する問題