我该怎么称呼'startActionMode'方法?

时间:2017-07-17 10:44:31

标签: java android

我想使用ActionMode来改变我的ActionBar。但我对package ferdos.androidui.activity; import android.os.Bundle; import android.support.v7.app.AppCompatActivity; import android.support.v7.view.ActionMode; import android.support.v7.widget.Toolbar; import android.view.Menu; import android.view.MenuItem; import android.view.View; import android.widget.Button; public class MainActivity extends AppCompatActivity { private ActionMode mActionMode; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); Toolbar toolbar = (Toolbar)findViewById(R.id.my_toolbar); //setSupportActionBar(toolbar); toolbar.inflateMenu(R.menu.menu2); Button btn = (Button)findViewById(R.id.button4); btn.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { mActionMode = MainActivity.this.startActionMode(new ActionBarCallBack()); } }); } class ActionBarCallBack implements ActionMode.Callback { @Override... } } 有疑问。它显示了一个错误:

  

错误:(28,65)错误:不兼容的类型:   MainActivity.ActionBarCallBack无法转换为Callback

我不知道如何将其作为样本使用。

Assuming you have a valid contactID, you can do this:

Cursor result = managedQuery(ContactsContract.Contacts.CONTENT_URI, null, 
         ContactsContract.Contacts._ID +" = ?", 
         new String[]{contactID}, null);      
if (result.moveToFirst()) {

    for(int i=0; i< result.getColumnCount(); i++){
        Log.i("CONTACTSTAG", result.getColumnName(i) + ": "
        + result.getString(i));
    }         
}
You will have to change the ContactsContract.Contacts.CONTENT_URI and the where clause to the table that you are querying. The above code will print out a bunch of general info about a contact.

1 个答案:

答案 0 :(得分:2)

要解决此问题,您必须将方法startActionMode替换为startSupportActionMode