English 中文(简体)
视像与活动分子的联系
原标题:Grid view image link to activites
  • 时间:2012-04-19 10:29:03
  •  标签:
  • java
  • android

我击中了一座砖瓦墙,我接着只是把图像放在点击上。

我想要做的是,对每一个形象来说,它开启了不同的活动。

比如,algebra图像打开了algebraactive,在点击露天活动等时,精度图像。

这可能很简单,但我目前并不十分清楚。

这里是主要活动。

import android.app.Activity; 
import android.content.Intent; 
import android.os.Bundle; 
import android.view.View; 
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener; 
import android.widget.GridView;  
public class MathsSubjectsActivity extends Activity {

    // Keep all Images in array
    public Integer[] mThumbIds = {
        R.drawable.algebraicon,R.drawable.coordsicon,
        R.drawable.decimalsicon,R.drawable.fractionsicon,
        R.drawable.algebraicon,R.drawable.algebraicon,
        R.drawable.powersicon,R.drawable.algebraicon,
        R.drawable.coordsicon,R.drawable.algebraicon,
    }; 

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.subjects);
        GridView gridView = (GridView) findViewById(R.id.grid_view); 
        // Instance of ImageAdapter Class 
        gridView.setAdapter(new ImageAdapter(this,mThumbIds)); 
 /**      * On Click event for Single Gridview Item      * */  
        gridView.setOnItemClickListener(new OnItemClickListener() {

            @Override
            public void onItemClick(AdapterView<?> parent, View v, int position, long id) {
                switch(position)
                {
                    case 0:
                        Intent login = new Intent(getApplicationContext(), MathsAlgebraActivity.class);
                        login.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
                        startActivity(login);
                        break;
                    case 1:
                        Intent coords = new Intent(getApplicationContext(), MathsMultiActivity.class);
                        coords.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
                        startActivity(coords);
                        break;
                    case 2:
                        Intent decim = new Intent(getApplicationContext(), MathsMultiActivity.class);
                        decim.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
                        startActivity(decim);
                        break;
                    //and so on for other activities.
                    default:
                        break;
                }
            }
        }); 
    }
}

以下是处理图像的图像改编器。

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.GridView;
import android.widget.ImageView;

private Context mContext;
private Integer[] resIds; 

//Constructor 
public ImageAdapter(Context c,Integer[] resIds){ 
    mContext = c;
    this.resIds=resIds;
}
@Override
public int getCount() {  
    return resIds.length;
}
@Override
public Object getItem(int position) {
    return resIds[position];
}
@Override
public long getItemId(int position) {
    return 0;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
    ImageView imageView = new ImageView(mContext); 
    imageView.setImageResource(resIds[position]);  
    imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);   
    imageView.setLayoutParams(new GridView.LayoutParams(70, 70)); 
    return imageView;
}
}

案件0,但不1或2。

误差:

    Thread [<1> main] (Suspended (exception ActivityNotFoundException)) 
Instrumentation.checkStartActivityResult(int, Object) line: 1405    
Instrumentation.execStartActivity(Context, IBinder, IBinder, Activity, Intent, int) line: 1379  
MathsSubjectsActivity(Activity).startActivityForResult(Intent, int) line: 2827  
MathsSubjectsActivity(Activity).startActivity(Intent) line: 2933    
MathsSubjectsActivity$1.onItemClick(AdapterView, View, int, long) line: 51  
GridView(AdapterView).performItemClick(View, int, long) line: 284   
AbsListView$PerformClick.run() line: 1812   
ViewRoot(Handler).handleCallback(Message) line: 587 
ViewRoot(Handler).dispatchMessage(Message) line: 92 
Looper.loop() line: 130 
ActivityThread.main(String[]) line: 3683    
Method.invokeNative(Object, Object[], Class, Class[], Class, int, boolean) line:     not available [native method]  
Method.invoke(Object, Object...) line: 507  
ZygoteInit$MethodAndArgsCaller.run() line: 839  
ZygoteInit.main(String[]) line: 597 
NativeStart.main(String[]) line: not available [native method]  
问题回答

尝试如下文法

gridView.setOnItemClickListener(new OnItemClickListener() {
    @Override
    public void onItemClick(AdapterView<?> parent, View v,
            int position, long id) {

         switch(position)
         {
             case 0:
             startActivity(context, FirstActivity.class);
             break;
             case 1:
             startActivity(context, SecondActivity.class);
             break;
             .....
             ...
         }
    }
});

EDIT1

    import android.app.Activity; 
        import android.content.Intent; 
        import android.os.Bundle; 
        import android.view.View; 
        import android.widget.AdapterView;
        import android.widget.AdapterView.OnItemClickListener; 
        import android.widget.GridView;  
        public class MathsSubjectsActivity extends Activity {   

        // Keep all Images in array
        public Integer[] mThumbIds = {        
        R.drawable.algebraicon,R.drawable.coordsicon,         
        R.drawable.decimalsicon,R.drawable.fractionsicon,  
        R.drawable.algebraicon,R.drawable.algebraicon,
        R.drawable.powersicon,R.drawable.algebraicon,        
        R.drawable.coordsicon,R.drawable.algebraicon, 
        }; 


         @Override    
         public void onCreate(Bundle savedInstanceState) {     
        super.onCreate(savedInstanceState);     
        setContentView(R.layout.subjects);  
        GridView gridView = (GridView) findViewById(R.id.grid_view); 
             // Instance of ImageAdapter Class    
        gridView.setAdapter(new ImageAdapter(this,mThumbIds)); 
             /**      * On Click event for Single Gridview Item      * */  
        gridView.setOnItemClickListener(new OnItemClickListener() {  

        @Override         
        public void onItemClick(AdapterView<?> parent, View v, int position, long id) {            
         switch(position)             
               {   
                case 0:                 
                   startActivity(this, AlgebraActivity.class);            
                        break;                    
                case 1:                   
                 startActivity(this, CoordsActivity.class);  
                                  break;    

                case 2: 
                startActivity(this,DecimalsActivity.class);
                break;
               //and so on for other activities.  
                default:
                break;                             

 } 


        }     
    }); 
    }   

} 

适应者希望:

import android.content.Context;   
import android.view.View; 
import android.view.ViewGroup;  
import android.widget.BaseAdapter; 
import android.widget.GridView;  
import android.widget.ImageView;       
 public class ImageAdapter extends BaseAdapter {    
private Context mContext;      
private Integer[] resIds; 
//Constructor 
 public ImageAdapter(Context c,Integer[] resIds){ 
mContext = c;    
this.resIds=resIds
}    
@Override                    
 public int getCount() {  
 return mThumbIds.length;                  
   }         
 @Override                   
public Object getItem(int position) {   
                      return mThumbIds[position];                     }     
  @Override                  
   public long getItemId(int position) {    
                     return 0;                  
   }                                    

      @Override            
         public View getView(int position, View convertView, ViewGroup parent) {                                
  ImageView imageView = new ImageView(mContext); 
 imageView.setImageResource(mThumbIds[position]);  
 imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);   
 imageView.setLayoutParams(new GridView.LayoutParams(70, 70)); 
 return imageView;                    
 }                                 
  }   

EDIT 2:

根据记录,人类病案卷中的活动没有条目。 您和roid曼病的以下活动:

<activity android:name="com.example.project.YourActivity"
                  . . . >
            . . .
        </activity>




相关问题
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 ...

热门标签