Set the Empty view of ListView
I found ListView control in Android is very easy to use, that is very good. Even there is a method to set the empty view, it will display it when the list context is empty.
You put any view in there. I put a LinearView with a Textview. That is easy!
Code
View empty= (View)view.findViewById(android.R.id.empty); | |
mListView.setEmptyView(empty); |
The Event in Fragment should be triggered when the fragment go to sleep
If you wish to do some actions, such as auto save, when the user go to other app, therefore the user put your app in a sleep mode at the background
You must override the onPause() method like below:
Code
@Override | |
public void onPause() { | |
super.onPause(); | |
if (!txtTitle.getText().equals("")) { | |
saveTag();; | |
} | |
} |
Stay in Android Studio 1.2, and keep away from 1.3 preview
At first, I upgrade my android studio to 1.3 preview from 0.8.6. I have not upgrade for ages, that is good to have the newest version. I have used their beta version for a while, android studio doesn't sound too bad even the version is still in beta. Thus, I used 1.3 preview rather than 1.2 stable. However, I spent some hours to upgrade my existing projects to work with this version of android studio. But I found their Gradle which has some problems to get google play ads library. Even I installed Google Support repository and Google Play library. Gradle still cannot find the ads library.
Finally, I gave up. I went back to Android Studio 1.2, then that is good all!
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 -->