2013-10-09 2 views
0

J'ai une classe de vue personnalisée gonflée XML. Il comprend des boutons et webview. J'ai ajouté cette viewclass à la mainactivity (VividViewerActivity). La première fois que j'ai mis la visibilité à invisible. Dans cette activité principale, il y a une méthode (loadPrintActivity) et je mets la visibilité de la classe view à visible. Tout fonctionne bien. Mais le contact ne fonctionne pas pour moi. Voici ma classe:L'événement tactile ne fonctionne pas pour la vue supérieure

public class PrintView extends RelativeLayout { 
Button btnClose,btnPrint; 
WebView wev; 
public PrintView(Context context) { 
    super(context); 
    // TODO Auto-generated constructor stub 
    View.inflate(context, R.layout.printscreen, this); 
    wev = (WebView) findViewById(R.id.webViewPrint); 
    btnClose = (Button)findViewById(R.id.btnClose); 
    btnPrint = (Button)findViewById(R.id.btnPrint); 
    btnClose.setOnClickListener(new View.OnClickListener() { 

     @Override 
     public void onClick(View v) { 
      // TODO Auto-generated method stub 
      Log.d("VIEWWWWWWWWWWWWWWWWWWWWW", "kaj korce.............."); 
      btnPrint.setVisibility(View.INVISIBLE); 
     } 
    }); 
} 


@Override 
public boolean onTouchEvent(MotionEvent event) { 
    // TODO Auto-generated method stub 
    return super.onTouchEvent(event); 
} 


@Override 
protected void onLayout(boolean changed, int l, int t, int r, int b) { 
    // TODO Auto-generated method stub 
    for(int i = 0 ; i < getChildCount() ; i++){ 
     getChildAt(i).layout(l, t, r, b); 
     } 
} 

Voici ma mise en page XML:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="fill_parent" 
android:layout_height="fill_parent" 
android:orientation="vertical" > 

<TableLayout 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" > 

    <TableRow 
     android:id="@+id/tableRow1" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:background="@drawable/top" 
     android:gravity="center" > 

     <RelativeLayout 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" > 

      <Button 
       android:id="@+id/btnClose" 
       android:layout_width="80dp" 
       android:layout_height="30dp" 
       android:layout_alignParentLeft="true" 
       android:layout_marginLeft="10dp" 
       android:background="@drawable/btn" 
       android:text="Close" /> 

      <Button 
       android:id="@+id/btnPrint" 
       android:layout_width="80dp" 
       android:layout_height="30dp" 
       android:layout_alignParentRight="true" 
       android:layout_marginRight="10dp" 
       android:background="@drawable/btn" 
       android:text="Print" /> 

     </RelativeLayout> 

    </TableRow> 

    <TableRow 
     android:id="@+id/tableRow2" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:layout_weight="1" > 

     <TableLayout 
      android:layout_width="fill_parent" 
      android:layout_height="fill_parent" 
      android:layout_weight="1" > 

      <TableRow 
       android:id="@+id/tableRow7" 
       android:layout_width="fill_parent" 
       android:layout_height="fill_parent" 
       android:layout_weight="1" > 

       <WebView 
        android:id="@+id/webViewPrint" 
        android:layout_width="fill_parent" 
        android:layout_height="fill_parent" 
        android:layout_weight="1" /> 

      </TableRow> 
     </TableLayout> 

    </TableRow> 
</TableLayout> 

Voici mon activité:

public class VividViewerActivity extends Activity{ 

private UnityPlayer mUnityPlayer; 

private JSInterface mJSInterface; // JavaScript interface (message receiver) 

private WebView mWebView;   // WebView object 
    private ProgressBar mProgress;  // Progress bar 
    private int mLeftMargin;   // Margins around the WebView 
    private int mTopMargin; 
    private int mRightMargin; 
    private int mBottomMargin; 
    private boolean mInitialLoad; 
    Context context; 

    PrintView pv; 

protected void onCreate (Bundle savedInstanceState) 
{ 
    super.onCreate(savedInstanceState); 

    requestWindowFeature(Window.FEATURE_NO_TITLE); 

    mUnityPlayer = new UnityPlayer(this); 

    context = this; 

    if (mUnityPlayer.getSettings().getBoolean ("hide_status_bar", true)) 
     getWindow().setFlags (WindowManager.LayoutParams.FLAG_FULLSCREEN, 
           WindowManager.LayoutParams.FLAG_FULLSCREEN); 

    int glesMode = mUnityPlayer.getSettings().getInt("gles_mode", 1); 
    boolean trueColor8888 = false; 
    mUnityPlayer.init(glesMode, trueColor8888); 

    View playerView = mUnityPlayer.getView(); 
    setContentView(playerView); 
    playerView.requestFocus(); 

    mJSInterface = new JSInterface();   

    Log.e("Cookie", "COOKIE SUPPORT!"); 

     mWebView = new WebView(this); 

     FrameLayout layout = new FrameLayout(this); 
     addContentView(layout, new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT)); 
     layout.addView(mWebView, new FrameLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT, Gravity.NO_GRAVITY)); 
     // Basic settings of WebView. 

     mWebView.setBackgroundColor(Color.TRANSPARENT); 

     WebSettings webSettings = mWebView.getSettings(); 
     webSettings.setSupportZoom(false); 
     webSettings.setJavaScriptEnabled(true); 
     webSettings.setPluginsEnabled(true); 



     mWebView.setWebViewClient(new WebViewClient(){}); 

     pv = new PrintView(context); 
     layout.addView(pv, new FrameLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT, Gravity.NO_GRAVITY)); 
     mWebView.addJavascriptInterface(mJSInterface, "UnityInterface"); 

     // Start in invisible state. 
     mWebView.setVisibility(View.GONE); 

     pv.setVisibility(View.INVISIBLE); 

} 

Voici la méthode:

public void loadPrintActivity(String printUrl){ 
    Constant.printUrl = printUrl; 
    Constant.isPrintButtonVisible = true; 
    WebSettings webSettings = pv.wev.getSettings(); 
    webSettings.setSupportZoom(true); 
    webSettings.setJavaScriptEnabled(true); 
    webSettings.setPluginsEnabled(true); 
    pv.wev.setWebViewClient(new WebViewClient(){}); 
    pv.wev.loadUrl(printUrl); 
    pv.setVisibility(View.VISIBLE); } 
+0

Y at-il quelqu'un qui peut m'aider? –

+0

Implémentez 'OnTouchListener' dans votre vue. – zanky

+0

@zanky Ça ne marche pas frère !!! –

Répondre

0

Changer votre point de vue du code comme celui-ci,

View v=View.inflate(context, R.layout.printscreen, this); 
    wev = (WebView) v.findViewById(R.id.webViewPrint); 
    btnClose = (Button)v.findViewById(R.id.btnClose); 
    btnPrint = (Button)v.findViewById(R.id.btnPrint); 
+0

Ce ne fonctionne pas frère .... Plz m'aider. –

0

Vous devez définir cette propriété en enfant et parent vue.

Dans parenview fichier Mise en page

android:clickable="true" 

Dans le fichier Childview Mise en page

android:clickable="false" 

Ce sera le travail.

+0

pourriez-vous s'il vous plaît dites-moi quelle position de mon fichier XML je dois mettre cela ?? –

+0

Définit la valeur true cliquable par le webview et le noeud chili par false. – Harshid

+0

Ça ne marche pas encore ........ –

Questions connexes