2016-04-10 3 views
0

я не знаю, как сделать .setParentLayout (GetWindow() .getDecorView()) Я использую библиотеку для того, чтобы сделать учебник пузыри, и когда пользователь делает длинный щелчок на элементе gridView, на котором появляется пузырь. Проблема в том, что я не знаю, как поставить context.getWindow() или что-то в этом роде, я не знаю, что подано перед getWindow().GetWindow() из контекста Android

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; 
} 
} 
+0

Включите ваш контекст для обслуживания, как YourActivity activity = (YourActivity) mContext; – Nepster

ответ

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

Я предполагаю, что ваш context является Activity так что вы можете сделать что-то вроде этого:

((Activity) context).getWindow() 

или вместо прохождения Context просто пройти Activity.

+4

Что делать, если ваш контекст не является активностью? –

Смежные вопросы