【发布时间】:2016-05-05 01:25:45
【问题描述】:
我在我的应用程序中实现了共享意图按钮。我在文本视图中有字符串,但它并不总是填充任何文本。所以,我想检查它是否为空。如果字符串为空,则共享意图应忽略/删除/获取该字符串并转到下一个字符串。我尝试以编程方式执行此操作,但没有成功。我怎样才能做到这一点?我需要一些帮助:
public void buttonClick2(View view) {
TextView textView1 = (TextView)findViewById(R.id.word);
TextView textView2 = (TextView)findViewById(R.id.definition);
TextView textView3 = (TextView)findViewById(R.id.definition2);
TextView textView4 = (TextView)findViewById(R.id.definition3);
boolean hasDefinition2 = false;
if (textView3 !=null){
String text3 = textView3.getText().toString();
if(text3 !=null && !text3.isEmpty()){
hasDefinition2 = true;
}
}
String def2 ="";
if(hasDefinition2){
def2 +="\n Definition 2: "+textView3.getText().toString();
}
boolean hasDefinition3 = false;
if (textView4 !=null){
String text4 = textView4.getText().toString();
if(text4 !=null && !text4.isEmpty()){
hasDefinition3 = true;
}
}
String def3 ="";
if(hasDefinition3){
def3 +="\n Definition 3: "+textView4.getText().toString();
}
Intent shareIntent1 = new Intent(android.content.Intent.ACTION_SEND);
shareIntent1.setAction(android.content.Intent.ACTION_SEND);
shareIntent1.setType("text/plain");
shareIntent1.putExtra(android.content.Intent.EXTRA_SUBJECT, "Word"); //<=adding blank quotes
shareIntent1.putExtra(Intent.EXTRA_TEXT, textView1.getText().toString()+
"\n"+Definition: +textView2.getText().toString()+
"\n"+def2+
"\n"+def3+
"\n"+"\n"+"@2016 Dictionary"+
"\n"+"Visit us:");
startActivity(Intent.createChooser(shareIntent1, "Share"));
}
【问题讨论】:
标签: android android-intent android-sharing