Android Studio Error :appcompat-v7:21.0.0': No resource found that matches the given name: attr "adnroid;XXXX"
After I upgraded my android studio from 0.86 and 1.2. I tried to build my project, I got a lot of errors like appcompat-v7:21.0.0': No resource found that matches the given name: attr: android :xxxx"
Actually, that is because appcompat-v7:21.0.0' required API 21. So, I need to install API 21 Platform SDK, Extra> Google Support Repository and Google Support Library.
The most important part, the part I missed, in the build.gradle set complie sdk to 21
Code
android { | |
compileSdkVersion 21 |
Display Objects in MultiAutoCompleteTextView
To display object value in MultiAutoCompleteTextView, you have to build a custom adapter:
For example, I have a tag class, which has Id field and name field.
Firstly, you need to have an adapter
Code
public View getView(int position, View convertView, ViewGroup parent) { | |
View v = convertView; | |
Holder holder; | |
if (v == null) { | |
LayoutInflater vi = (LayoutInflater) getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE); | |
v = vi.inflate(R.layout.autocomplete_layout, null); | |
holder= new Holder(); | |
| |
holder.Name=(TextView)v.findViewById(R.id.tagText); | |
convertView = v; | |
convertView.setTag(holder); | |
}else{ | |
holder=(Holder)convertView.getTag(); | |
} | |
Tag tag = items.get(position); | |
if (tag != null) { | |
holder.Name.setText(""+items.get(position).getTitle()); | |
TextView tagLabel = (TextView) v.findViewById(R.id.tagText); | |
if (tagLabel != null) { | |
tagLabel.setText(tag.getTitle()); | |
} | |
} | |
return v; | |
} | |
| |
private class Holder{ | |
| |
| |
public TextView Name; | |
| |
| |
} |
Then you need to change in CreateView at the fragment class
multiAutoCompleteTextView.setTokenizer(new MultiAutoCompleteTextView.CommaTokenizer());
List tagList = app.GetTags();
TagAdapter tagAdapter= new TagAdapter((Context)getActivity(),tagList);
multiAutoCompleteTextView.setThreshold(1);
multiAutoCompleteTextView.setAdapter(tagAdapter);
ck -->
Quick Fix for Android Studio - Alt+Enter
This is the first keyboard shortcut you need to learn if you use Android Studio. This is ALT+Enter. It opens to Quick Fix Menu, which has the suggestions about fixing the errors in the current line of code.
Like keyword in db.rawQuery with parameter
You can use "?" as the placeholder in sql for parameter in db.rawQuery in Android
For example
Code
String sql= "select Id , Name, Note from note | |
where Name = ?"; | |
Cursor c = db.rawQuery(sql, new String[] { name.toUpperCase() }); |
How about "Like" keyword with two "%".
You cannot do that :
Code
String sql= "select Id , Name, Note from note | |
where Name like %?%"; | |
Cursor c = db.rawQuery(sql, new String[] { name.toUpperCase() }); |
You have to do that like:
Code
String sql = "select from " + NoteTable.TABLE_NAME + " where upper(" + NoteTable.NoteColumns.NOTE + ") LIKE ? "; | |
Cursor c = db.rawQuery(sql, new String[] { "%"+name.toUpperCase() +"%" }); |
Id in onItemClick is not your Object Id
public abstract void onItemClick (AdapterView<?> parent, View view, int position, long id) in AdapterView
Last parameter calls id, but that will be row id, not the data object id in item.
You should use position and getItemAtPosition to get the data object in item you clicked. Then you can access id.
E.g.
Code
long noteId = ((Note)mListView.getItemAtPosition(position)).getId(); |