我已经在我的 android 中实现了网格视图,但我无法打开 chrome 自定义选项卡 在带有网络视图回退的网格视图中



我的主要活动.java其中包含网格视图方法,我们可以从中处理通过单击项目打开chrome自定义选项卡,但我无法执行此操作,因此请在这种情况下帮助我

public class MainActivity extends AppCompatActivity {
GridView gridView;

String[] gridViewString = {
        "Facebook", "Twitter", "Instagram", "Gmail", "Google+"};
int[] gridViewImageId = {R.drawable.facebook, R.drawable.twitter, R.drawable.instagram, R.drawable.gmail, R.drawable.googleplus};
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
CustomGridViewActivity customGridViewActivity = new CustomGridViewActivity(MainActivity.this, gridViewString, gridViewImageId);
gridView = (GridView) findViewById(R.id.column);
    gridView.setAdapter(customGridViewActivity);
    gridView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
    @Override
    public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
        switch (i) {
            case 0:
                Intent a = new Intent(getApplicationContext(), MainActivity.class);
                a.putExtra("id", l);
                a.putExtra("URL", "https://www.facebook.com");
                a.putExtra("Name", "Facebook");
                startActivity(a);
                break;
            default:
                break;
        }
    }
    });
}

}

这是我的网格视图适配器 Java 类

public class CustomGridViewActivity extends BaseAdapter {
private Context mContext;
private final String[] gridViewString;
private final int[] gridViewImageId;
private Object convertView;
public CustomGridViewActivity(Context context, String[] gridViewString, int[] gridViewImageId) {
    mContext= context;
    this.gridViewString = gridViewString;
    this.gridViewImageId = gridViewImageId;
}
@Override
public int getCount() {
    return gridViewString.length;
}
@Override
public Object getItem(int i) {
    return null;
}
@Override
public long getItemId(int i) {
    return 0;
}
@Override
public View getView(int i, View view, ViewGroup viewGroup) {
    View gridViewAndroid;
    LayoutInflater inflater=(LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);

    if (convertView == null)
    {
        gridViewAndroid=new View(mContext);
        gridViewAndroid=inflater.inflate(R.layout.structure,null);
        TextView textViewAndroid=(TextView) gridViewAndroid.findViewById(R.id.gridView_text);
        ImageView imageViewAndroid=(ImageView) gridViewAndroid.findViewById(R.id.gridView_image);
        textViewAndroid.setText(gridViewString[i]);
        imageViewAndroid.setImageResource(gridViewImageId[i]);
    }
    else {
        gridViewAndroid=(View) convertView;
    }
    return gridViewAndroid;
}

}

请帮助我通过网格视图的项目单击实现自定义选项卡

您正在尝试在onItemClick界面中再次打开"MainActivity"。

public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
    switch (i) {
        case 0:
            Intent a = new Intent(getApplicationContext(), MainActivity.class);///why are you trying to open MainActivity Again
            a.putExtra("id", l);
            a.putExtra("URL", "https://www.facebook.com");
            a.putExtra("Name", "Facebook");
            startActivity(a);
            break;
        default:
            break;
    }
}

样本

public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
    switch (i) {
        case 0:
             CustomTabsIntent customTabsIntent = new 
             CustomTabsIntent.Builder().build();
             CustomTabActivityHelper.openCustomTab(
                this,// activity
                customTabsIntent,
                Uri.parse("http://www.google.com"), 
                new WebviewFallback());
    default:
    break;
    }
}

请参阅此处以从您的活动中打开自定义版式标签页

相关内容

  • 没有找到相关文章

最新更新