Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/230.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 如何在自定义listview中共享文本?_Android_Listview_Share_Custom Lists - Fatal编程技术网

Android 如何在自定义listview中共享文本?

Android 如何在自定义listview中共享文本?,android,listview,share,custom-lists,Android,Listview,Share,Custom Lists,在这个程序中,我有一个自定义的列表视图,包括一个文本视图&一个图像按钮! 我想在SQLite数据库中共享一个文本,但我不知道如何共享 如果你能帮我做些指导,我会非常感激的 public class danestaniha_list extends ListActivity { private String txt=""; private TextView titrtext; private static final String[] items1 =

在这个程序中,我有一个自定义的
列表视图
,包括一个
文本视图
&一个
图像按钮
! 我想在
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 ..."));

        }

    });

    }
}
公共类danestaniha_列表扩展ListActivity{
私有字符串txt=“”;
私有文本视图标题文本;
私有静态最终字符串[]items1={“测试文本1”、“测试文本2”、“测试文本3”};
私有静态最终字符串[]items2={“测试文本1”、“测试文本2”、“测试文本3”};
私有静态最终字符串[]items3={“测试文本1”、“测试文本2”、“测试文本3”};
私有静态最终字符串[]items4={“测试文本1”、“测试文本2”、“测试文本3”};
私有静态最终字符串[]items5={“测试文本1”、“测试文本2”、“测试文本3”};
创建时受保护的void(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.list);
Bundle extras=getIntent().getExtras();
titrtext=(TextView)findViewById(R.id.pm_titrtext);
字符串值1=extras.getString(“titrtext”);
字符串值2=extras.getString(“部分”);
titrtext.setText(值1);
int value2i=Integer.parseInt(value2.toString());
如果(值2i==1){
setListAdapter(新的ArrayAdapter(this,R.layout.items,R.id.txt_pm,items1));
}
如果(值2i==2){
setListAdapter(新的ArrayAdapter(this,R.layout.items,R.id.txt_pm,items2));
}
如果(值2i==3){
setListAdapter(新的ArrayAdapter(this,R.layout.items,R.id.txt_pm,items3));
}
如果(值2i==4){
setListAdapter(新的ArrayAdapter(this,R.layout.items,R.id.txt_pm,items4));
}
如果(值2i==5){
setListAdapter(新阵列适配器(this,R.layout.items,R.id.txt_pm,items5));
}
}
public void onListItemClick(ListView父视图、视图v、整数位置、长id){
ImageButton btn_共享=(ImageButton)findViewById(R.id.img_共享);
btn_share.setOnClickListener(新的OnClickListener(){
@凌驾
公共void onClick(视图arg0){
意向共享意向=新意向(意向.行动\发送);
shareIntent.setType(“文本/普通”);
shareIntent.putExtra(Intent.EXTRA_TEXT,titrtext.ge tText().toString());
shareIntent.putExtra(Intent.EXTRA_主题,“伊朗”);
startActivity(Intent.createChooser(shareIntent,“与…共享”);
}
});
}
}
试着这样使用

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();
        }
    }

“分享”是什么意思?你的问题不清楚。这里没有任何与SQLite数据库相关的代码。请粘贴与数据库相关的代码。我相信OP希望使用ListView显示数据库内容。如果是这种情况,您可以查看以下教程:如果您想在SQLITE数据库上共享,那么您必须使用它。您会共享您的活动布局吗?