2017-02-21 1 views
0

до вводаКак я идти о том, выпадающем в андроиде

barcode: ____________ 
QTY: ________________ 

после ввода

, когда штрих-код имеет обнаружить вход состоят записи

barcode:______apple______ 

+ apple1  + apple2  +apple3  +apple4 

QTY:______________________ 

+ представляет собой интерактивный круг кнопка.

Какой метод вы предлагаете. падать? но не будут затронуты оба QTY?

ответ

1

Вы можете использовать Android PopupWindow шоу в списке

видят в этом связывает http://rajeshandroiddeveloper.blogspot.in/2013/07/android-popupwindow-example-in-listview.html

android.widget.PopupWindow может быть использован для отображения произвольного вида. Всплывающее окно представляет собой плавающий контейнер, который появляется поверх текущей активности.

Я собираюсь объяснить, как использовать popupwindow в виде списка. Например, в элементе listview у вас есть кнопка с подробными сведениями, что вы можете использовать этот popupwindow для отображения этих деталей в этом окне. Давайте посмотрим, как это сделать.

Шаг 1: main.xml

Вы можете использовать либо в виде списка или любые другие композитные ListViews:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    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=".MainActivity" > 

    <LinearLayout android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:gravity="right" 
     android:orientation="vertical" 
     > 
     <ListView 
      android:id="@+id/listView1" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" > 
     </ListView> 

     </LinearLayout> 

</RelativeLayout> 

Шаг 2: listviewchild.xml Вы можете создать свой собственный вид.

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/linear_item" 
    android:layout_width="fill_parent" 
    android:layout_height="100dp"  

    android:gravity="right" 
    android:orientation="vertical" > 

    <ImageView 
     android:id="@+id/imageView1" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignParentTop="true" 
     android:layout_marginLeft="15dp"   
     android:layout_toRightOf="@+id/textview_name" 
     android:src="@drawable/ic_launcher" /> 

</RelativeLayout> 

Шаг 3:

Ваш MainActivity.java

import java.util.ArrayList; 
import java.util.List; 

import android.app.Activity; 
import android.content.Context; 
import android.graphics.Color; 
import android.os.Bundle; 
import android.view.LayoutInflater; 
import android.view.View; 
import android.view.View.OnClickListener; 
import android.view.ViewGroup; 
import android.view.WindowManager; 
import android.widget.ArrayAdapter; 
import android.widget.BaseAdapter; 
import android.widget.ImageView; 
import android.widget.ListView; 
import android.widget.PopupWindow; 
import android.widget.TextView; 

public class MainActivity extends Activity { 

    String TAG = "MainActivity.java"; 

    String popUpContents[]; 
    PopupWindow popupWindowDogs; 
    ListView listView1; 

    @Override 
    protected void onCreate(Bundle savedInstanceState) { 

     super.onCreate(savedInstanceState); 
     setContentView(R.layout.activity_main); 

     listView1=(ListView)findViewById(R.id.listView1); 
     listView1.setAdapter(new MyAddapter(MainActivity.this)); // binding the list view. 
     /* 
     * initialize pop up window items list 
     */ 

     // add items on the array dynamically 
     // format is Company Name:: ID 
     List<String> dogsList = new ArrayList<String>(); 
     dogsList.add("Samsung"); 
     dogsList.add("Google"); 
     dogsList.add("Yahoo"); 
     dogsList.add("Microsoft"); 

     // convert to simple array 
     popUpContents = new String[dogsList.size()]; 
     dogsList.toArray(popUpContents); 

     /* 
     * initialize pop up window 
     */ 
     popupWindowDogs = popupWindowDogs(); 


    } 

    /* 
    * 
    */ 
    public PopupWindow popupWindowDogs() { 

     // initialize a pop up window type 
     PopupWindow popupWindow = new PopupWindow(this); 

     // the drop down list is a list view 
     ListView listViewDogs = new ListView(this); 

     // set our adapter and pass our pop up window contents 
     listViewDogs.setAdapter(dogsAdapter(popUpContents)); 

     // set the item click listener 
     listViewDogs.setOnItemClickListener(new DogsDropdownOnItemClickListener()); 

     // some other visual settings 
     popupWindow.setFocusable(true); 
     popupWindow.setWidth(250); 
     popupWindow.setHeight(WindowManager.LayoutParams.WRAP_CONTENT); 

     // set the list view as pop up window content 
     popupWindow.setContentView(listViewDogs); 

     return popupWindow; 
    } 

    /* 
    * adapter where the list values will be set 
    */ 
    private ArrayAdapter<String> dogsAdapter(String dogsArray[]) { 

     ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, dogsArray) { 

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

       // setting the ID and text for every items in the list 

       String text = getItem(position);    

       // visual settings for the list item 
       TextView listItem = new TextView(MainActivity.this); 

       listItem.setText(text); 
       listItem.setTag(position); 
       listItem.setTextSize(22); 
       listItem.setPadding(10, 10, 10, 10); 
       listItem.setTextColor(Color.WHITE); 

       return listItem; 
      } 
     }; 

     return adapter; 
    } 
} 

Шаг 4: Ваш класс адаптер

class MyAddapter extends BaseAdapter { 
     Context rContext; 
     private LayoutInflater rInflater; 
     private Activity activity; 

     public MyAddapter(Context c) { 

      rInflater = LayoutInflater.from(c); 

      rContext = c; 

     }  

     public MyAddapter(Activity imagebinding) { 
      // TODO Auto-generated constructor stub 

      activity = imagebinding;   

      rContext = imagebinding; 
      rInflater = LayoutInflater.from(imagebinding); 
      rContext = imagebinding; 
      rInflater = (LayoutInflater) activity 
        .getSystemService(Context.LAYOUT_INFLATER_SERVICE); 



     } 

     @Override 
     public int getCount() { 
      // TODO Auto-generated method stub  


      return 10; 
     } 

     @Override 
     public Object getItem(int arg0) { 
      // TODO Auto-generated method stub 
      return null; 
     } 

     @Override 
     public long getItemId(int position) { 
      // TODO Auto-generated method stub 
      return 0; 
     } 

     @Override 
     public View getView(final int position, View convertView, 
       ViewGroup parent) { 
      // TODO Auto-generated method stub 
      convertView = rInflater.inflate(R.layout.child, null); 
      final MyDat mydat = new MyDat();  

      mydat.imageView1=(ImageView)convertView.findViewById(R.id.imageView1); 
      mydat.imageView1.setOnClickListener(new OnClickListener() { 

       @Override 
       public void onClick(View v) { 
        // TODO Auto-generated method stub 
        popupWindowDogs.showAsDropDown(v, -5, 0); 

       } 
      }); 

      return convertView; 
     } 

     class MyDat { 



      ImageView imageView1; 


     } 

    } 

Шаг 5: Ваши пункты всплывающих окон Нажмите слушателю

Вы можете использовать это, если хотите продолжить движение для переходов активности.

import android.content.Context; 
import android.view.View; 
import android.view.animation.Animation; 
import android.view.animation.AnimationUtils; 
import android.widget.AdapterView; 
import android.widget.AdapterView.OnItemClickListener; 
import android.widget.Toast; 

public class DogsDropdownOnItemClickListener implements OnItemClickListener { 

    @Override 
    public void onItemClick(AdapterView<?> arg0, View v, int arg2, long arg3) { 

     // get the context and main activity to access variables 
     Context mContext = v.getContext(); 
     MainActivity mainActivity = ((MainActivity) mContext); 

     // add some animation when a list item was clicked 
     Animation fadeInAnimation = AnimationUtils.loadAnimation(v.getContext(), android.R.anim.fade_in); 
     fadeInAnimation.setDuration(10); 
     v.startAnimation(fadeInAnimation); 

     // dismiss the pop up 
     mainActivity.popupWindowDogs.dismiss(); 

     // get the text and set it as the button text 

     Toast.makeText(mContext, "Selected Positon is: " + arg2, 100).show(); 


    } 

} 
+0

хорошо, спасибо, я посмотрю – Chris