我使用fileselectActivity选择不同的文件路径和意图回到mainActivity,意图会多次跳转,因为我必须向Edittext插入多个文件路径,问题是现在我无法获取Edittext值和长度
Here is my code.
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.decryption_activity);
privatekeypathedit = (EditText) findViewById(R.id.privatekeypathEdittext);
targetfilepathedit = (EditText) findViewById(R.id.targetfilepathEdit);
privatekeypath(); //Button
targetfilepath();//Button
startdecryption();//Button
Intent intent = getIntent();
String filepath = intent.getStringExtra("filepath");
Toast.makeText(this, privatekeypathedit.getText(), Toast.LENGTH_LONG).show();//Here is empty
Toast.makeText(this, targetfilepathedit.getText(), Toast.LENGTH_LONG).show();//Here is empty
if (privatekeypathedit.getText().length() == 0) {//i think here still not working
privatekeypathedit.setText(filepath);
} else if (targetfilepathedit.getText().length() == 0) {
targetfilepathedit.setText(filepath);
}
System.out.println("Test##############"+privatekeypathedit.getText().toString());//null
System.out.println("Test##############"+targetfilepathedit.getText().toString());//null
}
这是我的布局文件。
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<EditText
android:id="@+id/privatekeypathEdittext"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<requestFocus />
</EditText>
<Button
android:id="@+id/publickeyselectButton"
style="?android:attr/buttonStyleSmall"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Select private key file(.pfx)" />
<EditText
android:id="@+id/targetfilepathEdit"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<requestFocus />
<Button
android:id="@+id/targetfileselectButton"
style="?android:attr/buttonStyleSmall"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Select target file" />
<EditText
android:id="@+id/privatekeypasswordedit"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<requestFocus />
<Button
android:id="@+id/startdecryptionButton"
style="?android:attr/buttonStyleSmall"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Start Decryption" />
</LinearLayout>
fileSelectActivity
private void onFileClick(Option o)
{
Toast.makeText(this, "You selected "+o.getName(), Toast.LENGTH_SHORT).show();
Intent intent = new Intent(selectddecrypfile.this,decryptActivity.class);
intent.putExtra("filepath", o.getPath());
startActivity(intent);
}
答案 0 :(得分:1)
尝试:
(privatekeypathedit.getText().toString()).equals("");
或
(privatekeypathedit.getText().toString()).lenght()==0;
答案 1 :(得分:0)
试试这个:希望这会对你有所帮助
Toast.makeText(this, privatekeypathedit.getText().toString(), Toast.LENGTH_LONG).show();
Toast.makeText(this, targetfilepathedit.getText().toString(), Toast.LENGTH_LONG).show();