2015-04-07 4 views
0

J'ai une question simple, je suis nouveau chez android et je me demande comment pourrais-je faire pour montrer à un utilisateur un message simple après un long clic dans l'un des suivants boutons. L'idée est de montrer à l'utilisateur le mot de passe qu'il utilise sur chacun des sites après un long clic. Des idées? Merci d'avance;)Comment afficher les messages pop-up dans android après longclick

public class MainMenu extends ActionBarActivity { 
    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.main_menu); 
     setTitle("Main Menu"); 
    } 
    @Override 
    public boolean onCreateOptionsMenu(Menu menu) { 
     // Inflate the menu; this adds items to the action bar if it is present. 
     getMenuInflater().inflate(R.menu.main_menu, menu); 
     return true; 
    } 
    @Override 
    public boolean onOptionsItemSelected(MenuItem item) { 
     // Handle action bar item clicks here. The action bar will 
     // automatically handle clicks on the Home/Up button, so long 
     // as you specify a parent activity in AndroidManifest.xml. 
     int id = item.getItemId(); 
     if (id == R.id.action_settings) { 
      return true; 
     } 
     return super.onOptionsItemSelected(item); 
    } 
    public void openWeb1(View v){ 
     startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.ljmu.ac.uk/"))); 
    } 

    public void openWeb2(View v){ 
     startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.bbc.co.uk"))); 
    } 
    public void openWeb3(View v){ 
     startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.facebook.com"))); 
    } 

    public void openWeb4(View v){ 
     startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.adidas.com"))); 
    } 

    public void openWeb5(View v){ 
     startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.stackoverflow.com"))); 
    } 

    public void addNew(View v){ 

    } 

} 
The XML code: 
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    xmlns:android1="http://schemas.android.com/apk/res/android" 
    android:id="@+id/GridView1" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:paddingBottom="@dimen/activity_vertical_margin" 
    android:paddingLeft="@dimen/activity_horizontal_margin" 
    android:paddingRight="@dimen/activity_horizontal_margin" 
    android:paddingTop="@dimen/activity_vertical_margin" 
    tools:context="net.androidbootcamp.myunimanager.MainMenu" > 
    <LinearLayout 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:orientation="vertical" > 
     <Button 
      android1:id="@+id/btnLJMU" 
      android1:layout_width="290dp" 
      android1:layout_height="76dp" 
      android1:drawableRight="@drawable/profile" 
      android1:onClick="openWeb1" 
      android1:text="Liverpool JMU" /> 
     <Button 
      android1:id="@+id/btnBBC" 
      android1:layout_width="match_parent" 
      android1:layout_height="76dp" 
      android1:drawableRight="@drawable/contacts" 
      android1:onClick="openWeb2" 
      android1:text="BBC News" /> 
     <Button 
      android1:id="@+id/btnFACEBOOK" 
      android1:layout_width="match_parent" 
      android1:layout_height="76dp" 
      android1:drawableRight="@drawable/courses" 
      android1:onClick="openWeb3" 
      android1:text="facebook" /> 
     <Button 
      android:id="@+id/btnADIDAS" 
      android:layout_width="112dp" 
      android:layout_height="0dp" 
      android:drawableRight="@drawable/calendar" 
      android1:onClick="openWeb4" 
      android1:text="adidas" /> 
     <Button 
      android1:id="@+id/btnSTACKOVERFLOW" 
      android1:layout_width="match_parent" 
      android1:layout_height="76dp" 
      android1:drawableRight="@drawable/notes" 
      android1:onClick="openWeb5" 
      android1:text="StackOverFlow" /> 
     <Button 
      android1:id="@+id/btnADDNEW" 
      android1:layout_width="match_parent" 
      android1:layout_height="78dp" 
      android1:onClick="addNew" 
      android1:drawableRight="@drawable/myuni" 
      android1:text="Add New" /> 
    </LinearLayout> 
</ScrollView>* 

Répondre

0

Avoir un LongClickListener pour le bouton. A l'intérieur, vous pouvez exécuter l'action correspondante en affichant une fenêtre contextuelle.

button.setOnLongClickListener(new OnLongClickListener() { 
      @Override 
      public boolean onLongClick(View v) { 
       // TODO Auto-generated method stub 
       return true; 
      } 
     }); 

Vérifiez les points suivants pour savoir comment créer des messages contextuels.

Espérons que cela aide!