English 中文(简体)
如何开始使用 活动 在ArrayAdapter 班级中恢复通话方法?
原标题:How can i used startActivityForResult in getView method in ArrayAdapter class?

我想用开端从阿雷拉Adapter类别中说另一个意图。 活动 但对结果,但一刀切。 这里是我的法典。

ArrayAdapter class Constructor

public QsShareManagerAdapter(Context context, String[] values, Long[] size,String[] time,
        boolean isRoot, Boolean[] attrdir, ArrayList<Boolean> selected,boolean type,
        LinearLayout linearLayout,String SHARE,String qsUsername) 
{
    super(context, R.layout.listlayout, values);
    this.context = context;
    this.values = values;
    this.size = size;
    this.time=time;
    this.isRoot = isRoot;
    this.attrdir = attrdir;
    this.selected = selected;
    this.type=type;
    this.linearLayout=linearLayout;
    this.SHARE=SHARE;
    this.qsUsername=qsUsername;
}





    @Override
public View getView(final int position, View convertView, ViewGroup parent) 
{
    String spliter = "/";
    tag=SHARE.split(spliter);

    LayoutInflater inflater = (LayoutInflater) context
            .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    View rowView = inflater.inflate(R.layout.listlayout, parent, false);

    //
    addFiles=(Button)linearLayout.findViewById(R.id.add_files);
    manageUser=(Button)linearLayout.findViewById(R.id.manage_users);
    deleteSharedFolder=(Button)linearLayout.findViewById(R.id.delete_shared_folder);
    copyFiles=(Button)linearLayout.findViewById(R.id.copy);
    deleteFiles=(Button)linearLayout.findViewById(R.id.delete_files);

    addFiles.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub
              Intent intent=new Intent(context,QsFileSelector.class).setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);  ;
              intent.putExtra(QsFileSelector.SELECTED_FILES,existing_seletedFile);
              intent.putExtra(QsFileSelector.FILE_OR_DIRECTORY, tag[6]);
              startActivityForResult(intent); 
            Toast.makeText(context, "Add Files", Toast.LENGTH_SHORT).show();
        }
    });

    manageUser.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub
            Toast.makeText(context, "Manage User", Toast.LENGTH_SHORT).show();              
        }
    });

    deleteSharedFolder.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub
              boolean status=serverURL.folderRequestResponseURI("DELETED_CREATOR", tag[6], qsUsername, tag[5], null, "");
              if(status){
                  Toast.makeText(context, "Delete Share Folder", Toast.LENGTH_SHORT).show();
              }
        }
    });

    copyFiles.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub
            Toast.makeText(context, "Copy", Toast.LENGTH_SHORT).show();
        }
    });

    deleteFiles.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub
            Toast.makeText(context, "Delete", Toast.LENGTH_SHORT).show();
        }
    });


    TextView textView = (TextView) rowView.findViewById(R.id.txtview);
    ImageView imageView = (ImageView) rowView.findViewById(R.id.icon);
    TextView sizeView = (TextView) rowView.findViewById(R.id.size);

    final CheckBox checkbox = (CheckBox) rowView
            .findViewById(R.id.checkbox);

    String s = values[position];

    checkbox.setOnCheckedChangeListener(new OnCheckedChangeListener() 
    {
        int postion=position;
        @Override
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) 
        {
            // TODO Auto-generated method stub
            if(isChecked){
                addToList(values[postion],true);
            }else{
                addToList(values[postion],false);                   
            }
        }
    });
    rowView.setTag(s);
    if (!values[position].contains("my_shared_folder") && isRoot && type) 
    {
        s = values[position] + "  s Shared Folder";
        textView.setText(s);
    } 
    else 
    {
        textView.setText(values[position]);
    }

    if (size.length != 0)
    {
        double sizeinKb = size[position] / 1024;

        if (sizeinKb > 1024) {
            double sizeinMb = sizeinKb / 1024;
            sizeView.setText(Double.toString(round(sizeinMb, 2,
                    BigDecimal.ROUND_HALF_UP)) + " MB | "+time[position]);
        }

        else if (sizeinKb > 1048576) {
            double sizeinGB = sizeinKb / (1024 * 1024);
            sizeView.setText(Double.toString(round(sizeinGB, 2,
                    BigDecimal.ROUND_HALF_UP)) + " GB | "+time[position]);
        }

        else {
            sizeView.setText(Double.toString(round(sizeinKb, 2,
                    BigDecimal.ROUND_HALF_UP)) + " KB | "+time[position]);
        }

    }

    if (attrdir[position]) 
    {
        imageView.setImageResource(R.drawable.icon_folder_logo);
        sizeView.setText("");
    }
    else 
    {
        checkbox.setVisibility(View.VISIBLE);
        if (s.contains(".mp3") || s.contains(".wav")) 
        {
            imageView.setImageResource(R.drawable.audio);
        }
        else if (s.contains(".zip") || s.contains(".rar")
                || s.contains(".tar")) 
        {
            imageView.setImageResource(R.drawable.zip);
        }
        else if (s.contains(".db")) 
        {
            imageView.setImageResource(R.drawable.db_icon);
        }
        else if ((s.contains(".png")) || (s.contains(".jpg"))) 
        {
            imageView.setImageResource(R.drawable.imagview);
        }
        else if ((s.contains(".doc")) || (s.contains(".docx"))) 
        {
            imageView.setImageResource(R.drawable.doc);
        }
        else if ((s.contains(".xls")) || (s.contains(".xlsx"))) 
        {
            imageView.setImageResource(R.drawable.excel);
        }
        else if ((s.contains(".pdf"))) 
        {
            imageView.setImageResource(R.drawable.pdf);
        }
        else 
        {
            imageView.setImageResource(R.drawable.unknown);
        }
    }
    /*
     * for(int i=0;i<size.size();i++){
     * sizeView.setText(Integer.toString(size.get(i))); }
     */     

    if(fileList.contains(values[position]) && checkStatus.contains(true)){
        linearLayout.setVisibility(View.VISIBLE);
        checkbox.setChecked(true);
    }

    if(fileList.size() == 0){
        linearLayout.setVisibility(View.GONE);
    }
    checkbox.setTag(values[position]);
    return rowView;
}
最佳回答
addFiles.setFocusable(false);

I think you should change Context to Activity...In your Adapter Constructor change it... activity.startActivityForResult(intent,position);

问题回答

使用<代码>context,并将此背景引向活动。 如:

((Activity)context).startActivityForResult(intent); 

用途

getApplicationContext().startActivityForResult(intent);

为什么要你? 你们有这种背景,利用了。

最新情况: 是否将其投入活动或改变类型。

To achieve this you need context

((活动)内容)

如果你真的需要开始, 当时的活动就是如此。

context.startActivityForResult(intent, 1);





相关问题
Spring Properties File

Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...

Logging a global ID in multiple components

I have a system which contains multiple applications connected together using JMS and Spring Integration. Messages get sent along a chain of applications. [App A] -> [App B] -> [App C] We set a ...

Java Library Size

If I m given two Java Libraries in Jar format, 1 having no bells and whistles, and the other having lots of them that will mostly go unused.... my question is: How will the larger, mostly unused ...

How to get the Array Class for a given Class in Java?

I have a Class variable that holds a certain type and I need to get a variable that holds the corresponding array class. The best I could come up with is this: Class arrayOfFooClass = java.lang....

SQLite , Derby vs file system

I m working on a Java desktop application that reads and writes from/to different files. I think a better solution would be to replace the file system by a SQLite database. How hard is it to migrate ...

热门标签