我有framelayout一次在我Activity和其他时间的不同时间Fragment(经过相同framelayout的Activity)。
在 my 中MainActivity.class,我需要知道我的framelayout. 例如,我需要知道是否framelayout正在使用MyFragment1.class或MyFragment2.class。
我需要这样的东西(在这个例子中,log必须说我“你在 MyFragment1”):
FrameLayout frameLayout = (FrameLayout) findViewById(R.id.framelayout);
getSupportFragmentManager().beginTransaction()
.replace(R.id.framelayout,new MyFragment1())
.commit();
if (framelayout.getname.equals("package.MyFragment1.class"))
Log.d("debug", "you are in MyFragment1");
else if (framelayout.getname.equals("package.MyFragment2.class"))
Log.d("debug", "you are in MyFragment2");
Run Code Online (Sandbox Code Playgroud)
我怎样才能做到这一点?
我想比较我的联系人以获得字母顺序,但我有这个错误:
java.lang.IllegalArgumentException: Comparison method violates its general contract!
Run Code Online (Sandbox Code Playgroud)
当我打电话时发生这种情况
Collections.sort(aVoid, new CustomComparator());
Run Code Online (Sandbox Code Playgroud)
这是我的CustomComparator:
public class CustomComparator implements Comparator<ContactItems> {
@Override
public int compare(ContactItems o1, ContactItems o2) {
if (o1.getName() == null || o2.getName() == null)
return 0;
else
return o1.getName().toLowerCase().compareTo(o2.getName().toLowerCase());
}
}
Run Code Online (Sandbox Code Playgroud)
我的aVoid数组是@onPostExecute(List<ContactItems> aVoid)类的方法的结果AsyncTaskGetContacts extends AsyncTask<Void, Void, List<ContactItems>>