我想获取所选文件夹的位置并获取其ID ...它在列表视图中运行良好,但是现在我更改为recycleview,并且我不知道如何获取它的位置。
lst.setOnClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
// String folder = lst.getItemAtPosition( lst.getSelectedItemPosition()).toString();
String folder = (String) lst.getItemAtPosition(i);
String id = (String) lstMap.get(i);
Toast.makeText(getApplicationContext(),"Vous avez choisis "+ id,Toast.LENGTH_LONG).show();
String newReq= new StringBuilder().append(AppConfig.URL_GetFoldersFK).append(id).toString();
Log.d("Request show",newReq);
Intent intent = new Intent(MainActivity.this, BuildingsListActivity.class);
// Sending value to another activity using intent.
intent.putExtra("FolderId", newReq);
startActivity(intent);
}
});
答案 0 :(得分:0)
在RecyclerView
适配器中,您应该在onBindViewHolder()
方法中执行以下操作:
@Override
public void onBindViewHolder(final MyViewHolder holder, final int position){
String id = (String) lstMap.get(position);
holder.itemView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent intent = new Intent(mContext, BuildingsListActivity.class);
intent.putExtra("FolderId", id);
mContext.startActivity(intent);
}
});
}
答案 1 :(得分:0)
viewholder
将返回所选视图在position
中的位置。onBindViewHolder(...)
方法传递的 // Immutable Selection List of Users
.form-group
label.col-md-4.control-label Current Users
.col-md-4
.input-group
list-group#currentUsers(name='currentUsers')
for admin in config.admins
li.list-group-item #{admin}
.form-group
label.col-md-4.control-label Apply Changes
.col-md-4
.input-group
button.btn.btn-primary(type='submit') Save