Java 在android中:如何使Listview中的字符串启用复制 公共类mychatorderdetails扩展了ActionBarActivity{ 私人应用程序; 私有字符串顺序标识; 私有字符串orderdate; 私有字符串cust_name; 私有字

Java 在android中:如何使Listview中的字符串启用复制 公共类mychatorderdetails扩展了ActionBarActivity{ 私人应用程序; 私有字符串顺序标识; 私有字符串orderdate; 私有字符串cust_name; 私有字,java,android,string,listview,copy,Java,Android,String,Listview,Copy,在android中:如何使Listview中的字符串启用复制 公共类mychatorderdetails扩展了ActionBarActivity{ 私人应用程序; 私有字符串顺序标识; 私有字符串orderdate; 私有字符串cust_name; 私有字符串客户地址; 私有字符串cust_pincode; 专用字符串cust_mobile; 私人串动作; 私人字符串UPI; 专用按钮bt; 私人订单详情适用于oa; 私有ListView lv; 私有ArrayList消息列表; @凌驾 创建时

在android中:如何使Listview中的字符串启用复制
公共类mychatorderdetails扩展了ActionBarActivity{
私人应用程序;
私有字符串顺序标识;
私有字符串orderdate;
私有字符串cust_name;
私有字符串客户地址;
私有字符串cust_pincode;
专用字符串cust_mobile;
私人串动作;
私人字符串UPI;
专用按钮bt;
私人订单详情适用于oa;
私有ListView lv;
私有ArrayList消息列表;
@凌驾
创建时受保护的void(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.activity\u mychatorderdetails);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
messageList=newarraylist();
app=((MyApplication)getApplicationContext());
Bundle extras=getIntent().getExtras();
如果(附加值!=null){
order_id=extras.getString(“order_id”);
orderdate=extras.getString(“orderdate”);
cust_name=extras.getString(“cust_name”);
cust_address=extras.getString(“cust_address”);
cust_pincode=extras.getString(“cust_pincode”);
cust_mobile=extras.getString(“cust_mobile”);
UPI=extras.getString(“UPI”);
action=extras.getString(“action”);//setaccepted,setdelivered
}
bt=(按钮)findViewById(R.id.btnAction);
开关(动作)
{
案例“已交付”:{
bt.setText(“已交付”);
打破
}
案例“已接受”:{
bt.setText(“接受”);
打破
}
违约:
}
试一试{
字符串dpart=orderdate.substring(0,10);
字符串tpart=orderdate.substring(11,19);
orderdate=dpart.substring(8,10);
orderdate+=“/”+dpart.子字符串(5,7);
orderdate+=“/”+dpart.substring(0,4);
订单日期+=“”+t零件;
}
捕获(例外e)
{
Log.d(getString(R.string.app_name),e.getMessage());
}
HashMap行=新建HashMap();
行。输入(“类型”、“文本”);
行。put(“详细信息”,“订单ID:+订单ID”);
messageList.add(行);
HashMap rowd=新的HashMap();
第四行,输入(“类型”、“文本”);
第行put(“详细信息”,“订单日期:”+订单日期);
messageList.add(rowd);
HashMap row1=新的HashMap();
第1行。输入(“类型”、“文本”);
第1行。put(“详细信息”,客户名称);
messageList.add(第1行);
HashMap row2=新的HashMap();
第2行。输入(“类型”、“文本”);
第2行。put(“详细信息”,客户地址);
messageList.add(第2行);
HashMap row3=新的HashMap();
第3行。输入(“类型”、“文本”);
第3行。put(“详细信息”、“Pin:+cust_pincode”);
messageList.add(第3行);
HashMap row4=新的HashMap();
第4行。输入(“类型”、“文本”);
第4行。put(“详细信息”,“暴民:”+cust_mobile);
messageList.add(第4行);
HashMap row5=新的HashMap();
第5行。输入(“类型”、“文本”);
第5行。put(“详细信息”,“UPI:+UPI”);
messageList.add(第5行);
oa=新的OrderDetailsAdapter(mychatorderdetails.this,messageList);
lv=(ListView)findViewById(R.id.lstOrderDetails);
低压电源适配器(oa);
lv.setOnItemClickListener(新的AdapterView.OnItemClickListener(){
@凌驾
public void onItemClick(AdapterView父对象、视图、整型位置、长id){
试一试{
HashMap temp=新的HashMap();
temp=messageList.get(位置);
if(临时获取(“类型”)=“图像”)
{
//Uri=Uri.parse(temp.get(“details”);
showImage(临时获取(“详细信息”);
}
}捕获(例外e){
Log.d(getString(R.string.app_name),e.getMessage());
}
}
});
runOnUiThread(新的Runnable(){
@凌驾
公开募捐{
试一试{
JSONArray det=app.getMyChatOrderDetails(订单id);
对于(int i=0;ipublic class mychatorderdetails extends ActionBarActivity {
    private MyApplication app;
    private String order_id;
    private String orderdate;
    private String cust_name;
    private String cust_address;
    private String cust_pincode;
    private String cust_mobile;
    private String action;
    private String UPI;
    private Button bt;
    private OrderDetailsAdapter oa;
    private ListView lv;
    private ArrayList<HashMap<String, String>> messageList;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_mychatorderdetails);
        getSupportActionBar().setDisplayHomeAsUpEnabled(true);

        messageList = new ArrayList<HashMap<String, String>>();
        app=((MyApplication) getApplicationContext());

        Bundle extras = getIntent().getExtras();

        if(extras != null) {
            order_id = extras.getString("order_id");
            orderdate = extras.getString("orderdate");
            cust_name = extras.getString("cust_name");
            cust_address = extras.getString("cust_address");
            cust_pincode = extras.getString("cust_pincode");
            cust_mobile=extras.getString("cust_mobile");
            UPI=extras.getString("UPI");
            action=extras.getString("action"); //setaccepted, setdelivered
        }

        bt = (Button) findViewById(R.id.btnAction);
        switch (action)
        {
            case "setdelivered":{
                bt.setText("Delivered");
                break;
            }
            case "setaccepted":{
                bt.setText("Accept");
                break;
            }
            default:
        }

        try {
            String dpart = orderdate.substring(0, 10);
            String tpart = orderdate.substring(11, 19);
            orderdate = dpart.substring(8,10);
            orderdate+="/"+dpart.substring(5,7);
            orderdate+="/"+dpart.substring(0,4);
            orderdate+=" "+tpart;
        }
        catch (Exception e)
        {
            Log.d(getString(R.string.app_name), e.getMessage());
        }
        HashMap<String, String> row = new HashMap<String, String>();
        row.put("type", "text");
        row.put("details", "Order ID:"+order_id);
        messageList.add(row);
        HashMap<String, String> rowd = new HashMap<String, String>();
        rowd.put("type", "text");
        rowd.put("details", "Order Date:"+orderdate);
        messageList.add(rowd);
        HashMap<String, String> row1 = new HashMap<String, String>();
        row1.put("type", "text");
        row1.put("details",cust_name);
        messageList.add(row1);
        HashMap<String, String> row2 = new HashMap<String, String>();
        row2.put("type", "text");
        row2.put("details",cust_address);
        messageList.add(row2);
        HashMap<String, String> row3 = new HashMap<String, String>();
        row3.put("type", "text");
        row3.put("details","Pin:"+cust_pincode);
        messageList.add(row3);
        HashMap<String, String> row4 = new HashMap<String, String>();
        row4.put("type", "text");
        row4.put("details","Mob:"+cust_mobile);
        messageList.add(row4);
        HashMap<String, String> row5 = new HashMap<String, String>();
        row5.put("type", "text");
        row5.put("details","UPI:"+UPI);
        messageList.add(row5);
        oa=new OrderDetailsAdapter(mychatorderdetails.this,messageList);
        lv = (ListView) findViewById(R.id.lstOrderDetails);
        lv.setAdapter(oa);

        lv.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                try {
                    HashMap<String, String> temp = new HashMap<String, String>();
                    temp = messageList.get(position);
                    if(temp.get("type")=="image")
                    {
                        //Uri uri = Uri.parse(temp.get("details"));
                        showImage(temp.get("details"));
                    }

                } catch (Exception e) {
                    Log.d(getString(R.string.app_name), e.getMessage());
                }
            }
        });

        runOnUiThread(new Runnable() {
            @Override
            public void run() {
                    try {
                        JSONArray det = app.getMyChatOrderDetails(order_id);
                        for (int i = 0; i < det.length(); i++) {
                            JSONObject cat = det.getJSONObject(i);
                            HashMap<String, String> row = new HashMap<String, String>();
                            if(!TextUtils.isEmpty(cat.getString("msg_image").toString()))
                            {
                                row.put("type", "image");
                                row.put("details",cat.getString("msg_image").toString());
                            }
                            else
                            {
                                row.put("type", "text");
                                String mfv=cat.getString("msg_for_vendor").toString();
                                if(mfv.equals("1"))
                                {
                                    row.put("details","Customer: "+cat.getString("msg_text").toString());
                                }
                                else{
                                    row.put("details","Me: "+cat.getString("msg_text").toString());
                                }

                            }
                            messageList.add(row);
                        }

                        oa.notifyDataSetChanged();

                    } catch (JSONException e) {
                        Log.d(getString(R.string.app_name), e.getMessage());
                    } catch (Exception e) { //connection timeout
                        Log.d(getString(R.string.app_name), e.getMessage());
                        Toast.makeText(getApplicationContext(), e.getMessage(), Toast.LENGTH_LONG).show();
                    }
            }
        });
    }

    public void showImage(String imageUri) {
        Dialog builder = new Dialog(this);
        builder.requestWindowFeature(Window.FEATURE_NO_TITLE);
        builder.getWindow().setBackgroundDrawable(new ColorDrawable(android.graphics.Color.TRANSPARENT));
        builder.setOnDismissListener(new DialogInterface.OnDismissListener() {
            @Override
            public void onDismiss(DialogInterface dialogInterface) {
                //nothing;
            }
        });
        try {
            ImageView imageView = new ImageView(this);
            Bitmap bitmap = BitmapFactory.decodeStream((InputStream) new URL(imageUri).getContent());
            if (bitmap != null) {
                imageView.setImageBitmap(bitmap);
                LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(450, 400);
                imageView.setLayoutParams(layoutParams);
                imageView.setVisibility(View.VISIBLE);
                builder.addContentView(imageView, new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
                builder.show();
            }
        }
        catch (Exception e)
        {
            Log.d(getString(R.string.app_name), e.getMessage());
        }
    }

    public void doAction(View v)
    {
        switch (action)
        {
            case "setdelivered":{
                if(app.setOrderDelivered(order_id)) {
                    Toast.makeText(this,"Order marked as delivered...",Toast.LENGTH_LONG).show();
                    bt.setVisibility(View.INVISIBLE);
                }
                break;
            }
            case "setaccepted":{
                if(app.acceptChatOrder(order_id)){
                    Toast.makeText(this,"Order accepted...",Toast.LENGTH_LONG).show();
                    bt.setVisibility(View.INVISIBLE);
                }
                break;
            }
            default:
        }
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.menu_mychatorderdetails, 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();

        Intent intent;
        //noinspection SimplifiableIfStatement
        if (id == R.id.action_logout) {
            app = ((MyApplication) getApplicationContext());
            app.logOut();
            intent = new Intent(mychatorderdetails.this, LoginActivity.class);
            intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK);
            mychatorderdetails.this.startActivity(intent);
        }
        mychatorderdetails.this.finish();

        return super.onOptionsItemSelected(item);
    }
}
android:textIsSelectable="true"
myTextView.setTextIsSelectable(true);
tv.setOnLongClickListener(new View.OnLongClickListener() {

    @Override
    public boolean onLongClick(View v) {
        ClipboardManager clipboard = (ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE);
        ClipData clip = ClipData.newPlainText("", tv.getText());
        clipboard.setPrimaryClip(clip);
        Toast.makeText(context, "Copied to clipboard", Toast.LENGTH_SHORT).show();
        return true;
    }
});