2017-08-30 19 views
0

下部の各カードビューにコピーボタンと共有ボタンを追加する方法(スクリーンショットを参照)コピーと共有ボタンの実装方法

コピーアクティビティを実装する方法。 MainAcitity

はCategory_1.xml

public class MainActivity extends AppCompatActivity { 
ListView listView; 

@Override 
protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.activity_main); 

    listView = (ListView) findViewById(R.id.list); 
    String[] values = new String[]{"Programmer Status", "click 2", 
      "click 3", "click 4","click 5", 
    }; 

    ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, 
      android.R.layout.simple_list_item_1, android.R.id.text1, values); 

    listView.setAdapter(adapter); 

    listView.setOnItemClickListener(new AdapterView.OnItemClickListener() { 
     public void onItemClick(AdapterView<?> parent, View view, 
       int position, long id) { 
      if (position == 0) { 
       Intent myIntent = new Intent(view.getContext(), CategoryActivity1.class); 
       startActivityForResult(myIntent, 0); 
      } 
      if (position == 1) { 
       Intent myIntent = new Intent(view.getContext(), CategoryActivity2.class); 
       startActivityForResult(myIntent, 0); 
      } 
      if (position == 2) { 
       Intent myIntent = new Intent(view.getContext(), CategoryActivity3.class); 
       startActivityForResult(myIntent, 0); 
      } 
      if (position == 3) { 
       Intent myIntent = new Intent(view.getContext(), CategoryActivity4.class); 
       startActivityForResult(myIntent, 0); 
      } 
      if (position == 4) { 
       Intent myIntent = new Intent(view.getContext(), CategoryActivity5.class); 
       startActivityForResult(myIntent, 0); 
      } 
     } 
    }); 
} 
} 

私にいくつかのJavaとXMLのコードをお願いし
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" 
     xmlns:app="http://schemas.android.com/apk/res-auto" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent"> 

<android.support.v4.widget.NestedScrollView 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    app:layout_behavior="@string/appbar_scrolling_view_behavior"> 

    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:orientation="vertical" 
     android:paddingTop="10dp"> 

     <android.support.v7.widget.CardView 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:layout_margin="@dimen/card_margin"> 

      <LinearLayout 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:layout_margin="16dp" 
       android:orientation="vertical" 
       android:padding="5dp"> 

       <TextView 
        android:layout_width="match_parent" 
        android:layout_height="wrap_content" 
        android:text="@string/status_01"/> 

      </LinearLayout> 

     </android.support.v7.widget.CardView> 


    </LinearLayout> 

</android.support.v4.widget.NestedScrollView> 
を私はあまりにも多くの方法を試してみましたが、私は、私はコピーボタンを追加する方法任意のアイデアを持っていないことができません

CategoryActivity1

public class CategoryActivity1 extends AppCompatActivity { 
@Override 
protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.category_1); 
} 
} 

like this

+0

googleで検索してください。 –

+0

[ShareAction](https://developer.android)のこの[post](https://stackoverflow.com/questions/43262912/copy-to-clipboard-the-content-of-a-cardview)とこれを参照してください。 .com/training/sharing/shareaction.html) –

答えて

0

、このクリップ・ボード

ClipboardManager myClipboard; 
myClipboard = (ClipboardManager)getSystemService(CLIPBOARD_SERVICE); 
ClipData myClip; 
String text=textView.getText().toString(); 
myClip = ClipData.newPlainText("text", text); 
myClipboard.setPrimaryClip(myClip); 

にデータをコピーしようと、他のアプリケーションにクリップクリップボードからのデータを共有するための

ClipData abc = myClipboard.getPrimaryClip(); 
ClipData.Item item = abc.getItemAt(0); 
String text = item.getText().toString(); 

コードをこの貼り付けデータを使用します

ClipData abc = myClipboard.getPrimaryClip(); 
ClipData.Item item = abc.getItemAt(0); 
String text = item.getText().toString(); 

Intent sharingIntent = new Intent(android.content.Intent.ACTION_SEND); 
sharingIntent.setType("text/plain"); 
sharingIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, "Subject Here"); 
sharingIntent.putExtra(android.content.Intent.EXTRA_TEXT, text); 
startActivity(Intent.createChooser(sharingIntent,"Share with"); 
+0

私がTextViewを使用していない場合editText – Vicky

+0

テキストビューからテキストを取得することもできます。** **質問があれば教えてください** –

+0

how ?? plzzは細部を説明します – Vicky

関連する問題