在此计划中,我有一个自定义ListView
,其中包含TextView
&一个ImageButton
!
我想在SQLite
数据库中共享文本,但我不知道如何???
如果你能帮我一些指示,我真的很感激!
public class danestaniha_list extends ListActivity {
private String txt="";
private TextView titrtext;
private static final String[] items1 = {"Test Text 1","Test Text 2","Test Text 3"};
private static final String[] items2 = {"Test Text 1","Test Text 2","Test Text 3"};
private static final String[] items3 = {"Test Text 1","Test Text 2","Test Text 3"};
private static final String[] items4 = {"Test Text 1","Test Text 2","Test Text 3"};
private static final String[] items5 = {"Test Text 1","Test Text 2","Test Text 3"};
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.list);
Bundle extras = getIntent().getExtras();
titrtext=(TextView) findViewById(R.id.pm_titrtext);
String value1 = extras.getString("titrtext");
String value2 = extras.getString("part");
titrtext.setText(value1);
int value2i=Integer.parseInt(value2.toString());
if(value2i==1){
setListAdapter(new ArrayAdapter<String>(this,R.layout.items, R.id.txt_pm, items1));
}
if(value2i==2){
setListAdapter(new ArrayAdapter<String>(this,R.layout.items, R.id.txt_pm, items2));
}
if(value2i==3){
setListAdapter(new ArrayAdapter<String>(this,R.layout.items, R.id.txt_pm, items3));
}
if(value2i==4){
setListAdapter(new ArrayAdapter<String>(this,R.layout.items, R.id.txt_pm, items4));
}
if(value2i==5){
setListAdapter(new ArrayAdapter<String>(this,R.layout.items, R.id.txt_pm, items5));
}
}
public void onListItemClick(ListView parent, View v, int position, long id){
ImageButton btn_share = (ImageButton) findViewById(R.id.img_share);
btn_share.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
Intent shareIntent = new Intent(Intent.ACTION_SEND);
shareIntent.setType("text/plain");
shareIntent.putExtra(Intent.EXTRA_TEXT,titrtext.ge tText().toString());
shareIntent.putExtra(Intent.EXTRA_SUBJECT, "iran");
startActivity(Intent.createChooser(shareIntent, "share with ..."));
}
});
}
}
答案 0 :(得分:0)
尝试这样使用。
private void shareIt(String yourText) {
try {
Intent sendIntent = new Intent();
sendIntent.setAction(Intent.ACTION_SEND);
sendIntent.putExtra(Intent.EXTRA_TEXT, yourText);
sendIntent.setType("text/plain");
startActivity(sendIntent);
} catch (Exception e) {
e.printStackTrace();
}
}