我需要HashMap根据存储在其中的值对我进行排序.在HashMap包含存储在手机联系人的名字.
此外,我需要在对值进行排序时自动对键进行排序,或者您可以说键和值绑定在一起,因此值的任何更改都应该反映在键中.
HashMap<Integer,String> map = new HashMap<Integer,String>();
map.put(1,"froyo");
map.put(2,"abby");
map.put(3,"denver");
map.put(4,"frost");
map.put(5,"daisy");
Run Code Online (Sandbox Code Playgroud)
所需输出:
2,abby;
5,daisy;
3,denver;
4,frost;
1,froyo;
Run Code Online (Sandbox Code Playgroud) 我需要点击相应的按钮来调用最近的呼叫列表和最喜欢的呼叫列表,并且需要我自己的列表布局中的数据.我是Android的新手并且有很多麻烦.任何人请帮助我..提前谢谢..
我希望我的应用程序看起来像这样.我能够在两个不同的数组中获取名称和类型,但在code.names和type数组中标记的行获取空指针异常正在获取我想要的值.我已经仔细检查了我的布局文件,其中一个包含列表视图,另一个包含两个文本视图.任何帮助都会非常明显..
package application.test;
import java.util.HashMap;
import android.app.ListActivity;
import android.content.ContentResolver;
import android.database.Cursor;
import android.os.Bundle;
import android.provider.ContactsContract;
import android.widget.ListView;
public class TestActivity<types, names> extends ListActivity{
int count[];
int typecount[];
ListView lv;
ListViewAdapterrecent lva;
String[] names;
String[] types;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
lv=(ListView)findViewById(android.R.id.list);
ContentResolver tcr = getContentResolver();
Cursor tcur=tcr.query(ContactsContract.Data.CONTENT_URI, null, null, null, null);
HashMap<Integer, String> typehashmap=new HashMap<Integer, String>();
HashMap<Integer, String> namehashmap=new HashMap<Integer, String>();
if(tcur.getCount()>0)
{
while(tcur.moveToNext())
{
Boolean temp=false;
String …Run Code Online (Sandbox Code Playgroud)