RecyclerView.Adapter 点击事件

package gaga.erlan.apps.aiyesoft.com.gaga;

import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.LinearLayoutManager;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import org.xutils.x;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.TextView;
import android.widget.Toast;

import gaga.erlan.apps.aiyesoft.com.gaga.adapter.SelectAdapter.OnItemClickListener;
import gaga.erlan.apps.aiyesoft.com.gaga.adapter.SelectAdapter;

import static gaga.erlan.apps.aiyesoft.com.gaga.R.id.grid_title;


public class SelectActivity extends AppCompatActivity {

    private static JSONArray dataArr;
    private static JSONObject recordObj;
    SharedPreferences sharedPreferences;
    private String skill_gif, skill_phrase, skill_title;

    @ViewInject(R.id.select_gridview)
    private RecyclerView recycleView;

    private SelectAdapter myAdapter;

    //List容器包含项目列表要填充的数据
    private List<Map<JSONObject, Object>> list;

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

        x.view().inject(this);
        myAdapter = new SelectAdapter(this);
        recycleView.setLayoutManager(new LinearLayoutManager(this));
        recycleView.setAdapter(myAdapter);

	//Adapter点击方法
        myAdapter.setOnItemClickListener(new OnItemClickListener() {
            @Override
            public void OnItemClick(View view, int position) {
 
		//使用view.findViewById获取到对应的TextView值传递给其他Activity

                TextView grid_title = (TextView)view.findViewById(R.id.grid_title);
                TextView grid_phrase = (TextView)view.findViewById(R.id.grid_phrase);
		
		
		//使用switch (position) 对点击不同的item进行响应
/* switch (position) {
                   case 0: 
                       Toast.makeText(SelectActivity.this,"这是第一个"+grid_title.getText().toString()+"++++++++++++"+grid_phrase.getText().toString(),Toast.LENGTH_SHORT).show(); 
                       break; 
                   case 1:    
                       Toast.makeText(SelectActivity.this,"这是第二个"+grid_title.getText().toString()+"++++++++++++"+grid_phrase.getText().toString(),Toast.LENGTH_SHORT).show(); 
                       break;               
			 }*/               
			 Intent intent = new Intent();
	                 intent.setClass(SelectActivity.this, MainActivity.class);
	                 intent.putExtra("skill_title",grid_title.getText().toString());
	                 intent.putExtra("skill_phrase",grid_phrase.getText().toString());
	                 startActivity(intent);           
			 }       
 		});  
  	}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值