0

ここに画像の説明を入力してください

R.drawableファイルに保存されている画像のリストがあります。ユーザーが画像リストから1つの画像をクリックしたときに画像を共有したい。画像の表示リストと並べ替え順は以下の通りです。しかし、1つの画像をクリックすると、共有インテントが機能しません。

MyCode:

 public class MainActivity extends Activity {
         EditText edittext;
         ListView listview;
         ImageView imageview;

         String[] text = { "AbdulKalam", 
                 "AIGross", 
                 "AlbertAbrahamMichelson",
                  "AlbertEinstein", 
                 "AlbertHofmann",
                 "AlbrechtvonHaller", 
                 "AlessandroVolta",
                 "AlexanderCalder "};

    int[] image={R.drawable.abdul_kalam,
                         R.drawable.ai_gross,
                         R.drawable.albert_abraham_michelson,
                         R.drawable.albert_einstein,
                         R.drawable. albert_hofmann,
                         R.drawable. albrecht_von_haller,
                         R.drawable. alessandro_volta,
                         R.drawable. alexander_calder,
                         R.drawable. alexander_fleming};

     int textlength = 0;

                 ArrayList<String> text_sort = new ArrayList<String>();
                 ArrayList<Integer> image_sort = new ArrayList<Integer>();

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

            edittext = (EditText) findViewById(R.id.EditText01);
            final ListView  listview = (ListView) findViewById(R.id.ListView01);
              imageview=(ImageView)findViewById(R.id.ImageView01);




              listview.setAdapter(new MyCustomAdapter(text, image));




              edittext.addTextChangedListener(new TextWatcher()
              {

               public void afterTextChanged(Editable s)
               {

               }

               public void beforeTextChanged(CharSequence s, int start,
                int count, int after)
               {

               }

               public void onTextChanged(CharSequence s, int start,
                int before, int count)
               {

                textlength = edittext.getText().length();
                text_sort.clear();
                image_sort.clear();

                for (int i = 0; i < text.length; i++)
                {
                 if (textlength <= text[i].length())
                 {
                  if (edittext.getText().toString().
               equalsIgnoreCase((String) text[i].subSequence(0, textlength)))
                  {
                   text_sort.add(text[i]);
                   image_sort.add(image[i]);
                  }
                 }
                }

                listview.setAdapter(new MyCustomAdapter
                 (text_sort, image_sort));



               listview.setOnItemClickListener(new OnItemClickListener(){


                    @Override
                    public void onItemClick(AdapterView<?> parent, View view,
                            int position, long rowId) {
                        // TODO Auto-generated method stub
                        finalStringTouch=listview.getItemAtPosition(position).toString();
Intent sharingIntent = new Intent(Intent.ACTION_SEND);


                    sharingIntent.setType("image/png");
                     sharingIntent.putExtra("image",  Touch);

                    startActivity(Intent.createChooser(sharingIntent, "Share image using"));


                    }

                });

               }
              });
             }

             class MyCustomAdapter extends BaseAdapter
             {

              String[] data_text;
              int[] data_image;

              MyCustomAdapter()
              {

              }

              MyCustomAdapter(String[] text, int[] image)
              {
               data_text = text;
               data_image = image;
              }

              MyCustomAdapter(ArrayList<String> text, ArrayList<Integer> image)
              { 

               data_text = new String[text.size()];
               data_image = new int[image.size()];

               for(int i=0;i<text.size();i++)
               {
                data_text[i] = text.get(i);
                data_image[i] = image.get(i);
               }

              }

              public int getCount()
              {
               return data_text.length;
              }

              public String getItem(int position)
              {
               return null;
              }

              public long getItemId(int position)
              {
               return position;
              }

              public View getView(int position, View convertView, ViewGroup parent)
              {

               LayoutInflater inflater = getLayoutInflater();
               View row;

               row = inflater.inflate(R.layout.listview, parent, false);

               TextView textview = (TextView) row.findViewById(R.id.TextView01);
               ImageView imageview = (ImageView) row
                 .findViewById(R.id.ImageView01);

               textview.setText(data_text[position]);


               imageview.setImageResource(data_image[position]);



               return (row);

              }
             }
4

1 に答える 1

0

のドキュメントには余分な名前はありませ"image"ん。問題のイメージへのファイルシステム上のパスを提供して、イメージに使用する必要があります。結果として、私の知る限り、ドローアブル リソースを直接共有することはできません。それをファイルにコピーしてから、ファイルを共有する必要があります。ACTION_SENDEXTRA_STREAM

于 2012-10-08T11:25:57.590 に答える