0

我不知道怎么问题是我不知道如何放置 context.getWindow() 或类似的东西,我不知道在 getWindow() 之前应该是什么。

GridView_Adapter.class

package es.fingerlabs.gamecohol;

import android.app.Activity;
import android.content.ContentValues;
import android.content.Context;
import android.content.Intent;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.lovoo.tutorialbubbles.TutorialScreen;
import com.michael.easydialog.EasyDialog;

import java.util.ArrayList;

public class AdaptadorSobres extends BaseAdapter {

private Context context;
private ArrayList<Sobre> misSobres = new ArrayList<Sobre>();
private TutorialScreen botonTutorial;
private  View gridView;
public AdaptadorSobres(ArrayList<Sobre> list, Context context) {
    this.misSobres = list;
    this.context = context;
}

public View getView(final int position, final View convertView, ViewGroup parent) {

    gridView = convertView;
    if (gridView == null) {
        LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        gridView = inflater.inflate(R.layout.item_sobre, null);
    }

    TextView TextoNombreSobre = (TextView)gridView.findViewById(R.id.tvNombreSobre);
    TextoNombreSobre.setText(misSobres.get(position).getNombre());

    SobresSQLiteHelper sobresdbh = new SobresSQLiteHelper(context, "DBSobres", null, 1);
    SQLiteDatabase db = sobresdbh.getReadableDatabase();
    String[] args = new String[] {Integer.toString(misSobres.get(position).getId())};
    Cursor c = db.rawQuery(" SELECT seleccionado FROM Sobres WHERE id_sobre=? ", args);
    c.moveToFirst();
    final LinearLayout lyItemSobre = (LinearLayout) gridView.findViewById(R.id.lyItemSobre);
    if(c.getInt(0)==0){
        lyItemSobre.setBackgroundResource(R.drawable.rounded_corners_white);
    }else{
        lyItemSobre.setBackgroundResource(R.drawable.rounded_corners_yellow);
    }

    gridView.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            SobresSQLiteHelper sobresdbh = new SobresSQLiteHelper(context, "DBSobres", null, 1);
            SQLiteDatabase db = sobresdbh.getWritableDatabase();
            String[] args = new String[] {Integer.toString(misSobres.get(position).getId())};
            Cursor c = db.rawQuery(" SELECT comprado FROM Sobres WHERE id_sobre=? ", args);
            c.moveToFirst();
            if(c.getInt(0)==0){
                Intent intent = new Intent(context, ComprarSobre.class);
                intent.putExtra("Id", (misSobres.get(position).getId()));
                intent.putExtra("Nombre", (misSobres.get(position)).getNombre());
                intent.putExtra("Descripcion", (misSobres.get(position)).getDescripcion());
                context.startActivity(intent);
            }else{
                c = db.rawQuery(" SELECT seleccionado FROM Sobres WHERE id_sobre=? ", args);
                c.moveToFirst();
                if(c.getInt(0)==0){
                    lyItemSobre.setBackgroundResource(R.drawable.rounded_corners_yellow);
                    ContentValues valores = new ContentValues();
                    valores.put("seleccionado", 1);
                    db.update("Sobres", valores, "id_sobre=" + misSobres.get(position).getId(), null);
                }else{
                    lyItemSobre.setBackgroundResource(R.drawable.rounded_corners_white);
                    ContentValues valores = new ContentValues();
                    valores.put("seleccionado", 0);
                    db.update("Sobres", valores, "id_sobre=" + misSobres.get(position).getId(), null);
                }
            }
        }
    });

    gridView.setOnLongClickListener(new View.OnLongClickListener() {
        @Override
        public boolean onLongClick(View v) {
            botonTutorial.showTutorial();
            return false;
        }
    });

    gridView.post(new Runnable() {
        @Override
        public void run () {
            LayoutInflater lyInflater = LayoutInflater.from(context);
            botonTutorial = new TutorialScreen.TutorialBuilder(R.layout.tutorial_sobre, gridView)
                    .setParentLayout(getWindow().getDecorView())    // parent layout is necessary for layout approach, use decorView or a root relative layout
                    .setDismissible(true)                           // set if this bubble can be dismissed by clicking somewhere outside of its context
                    .addHighlightView(gridView, false)         // sets the view that should be explained
                    .setOnTutorialLayoutInflatedListener(new TutorialScreen.OnTutorialLayoutInflatedListener() {
                        // you can use this callback to bind the bubble layout and apply logic to it
                        @Override
                        public void onLayoutInflated ( View view ) {

                        }
                    })
                    .build();

        }
    });

    return gridView;
}

@Override
public int getCount() {
    return misSobres.size();
}

@Override
public Object getItem(int position) {
    return null;
}

@Override
public long getItemId(int position) {
    return 0;
}
}
4

1 回答 1

5
public AdaptadorSobres(ArrayList<Sobre> list, Context context) {
    this.misSobres = list;
    this.context = context;
}

我假设你context是一个Activity所以你可以做这样的事情:

((Activity) context).getWindow()

或者不是通过Context只是通过Activity

于 2016-04-10T16:19:06.503 回答