我创建了一个自定义列表视图。在其布局中创建了一个编辑文本。但我无法编辑此编辑文本。
list.setAdapter(new yourAdapter(NewActivity.this, new String[] { "test1",
"test2","test3" }));
我的yourAdapter类是
class yourAdapter extends BaseAdapter {
Context context;
String[] data;
private static LayoutInflater inflater = null;
public yourAdapter(Context context, String[] data) {
// TODO Auto-generated constructor stub
this.context = context;
this.data = data;
inflater = (LayoutInflater) context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
}
@Override
public int getCount() {
// TODO Auto-generated method stub
return data.length;
}
@Override
public Object getItem(int position) {
// TODO Auto-generated method stub
return data[position];
}
@Override
public long getItemId(int position) {
// TODO Auto-generated method stub
return position;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
// TODO Auto-generated method stub
View vi = convertView;
if (vi == null)
for(int i =0; i<=getCount();i++){
if(data[position].equals("grouped")){
vi = inflater.inflate(R.layout.multipleselect, null);
}
else if(data[position].equals("kuchbhi"))
vi = inflater.inflate(R.layout.yes_or_no, null);
else {
vi = inflater.inflate(R.layout.write_answer, null);
//edit_text
EditText edit_text = (EditText) vi.findViewById(R.id.edit_text);
}
}
/* TextView text = (TextView) vi.findViewById(R.id.text);
text.setText(data[position]);*/
return vi;
}
}
我无法在edit_text中进行编辑。当我点击编辑文本键盘打开但没有显示内部编辑文本。
答案 0 :(得分:0)
Marshmallow手动询问权限。毫无疑问,您必须已在清单文件中添加了位置权限,但现在您还需要添加一些代码以手动询问权限。 您可以使用此库 https://github.com/Karumi/Dexter
答案 1 :(得分:0)
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
if (checkPermission()) {
//do your work
} else {
requestPermission();
}
}
}
protected boolean checkPermission() {
int result = ContextCompat.checkSelfPermission(this, android.Manifest.permission.ACCESS_FINE_LOCATION);
if (result == PackageManager.PERMISSION_GRANTED) {
return true;
} else {
return false;
}
}
protected void requestPermission() {
if (ActivityCompat.shouldShowRequestPermissionRationale(this, android.Manifest.permission.ACCESS_FINE_LOCATION)) {
Toast.makeText(this, "Write External Storage permission allows us to do store images. Please allow this permission in App Settings.", Toast.LENGTH_LONG).show();
} else {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
requestPermissions(new String[]{android.Manifest.permission.ACCESS_FINE_LOCATION}, 100);
}
}
}
@Override
public void onRequestPermissionsResult(int requestCode, String permissions[], int[] grantResults) {
switch (requestCode) {
case 100:
if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
//do your work
} else {
Log.e("value", "Permission Denied, You cannot use local drive .");
}
break;
}
}