问:
How to set the setTag() method for each listItem in ListView
I created a MainActivity that holds the list of player names.When I click to that list_item need to  setTag() method for each of the clicked item and that should call the SubActivity.In SubActivity how to implement MediaPlayer and how  to get those Tag.

MainActivity :

```public class MainActivity extends AppCompatActivity {

     String[] audioTitels;
     ListView listView;

     @Override
     protected void onCreate(Bundle savedInstanceState) {
         super.onCreate(savedInstanceState);
         setContentView(R.layout.activity_main);

         Resources res = getResources();
         audioTitels = res.getStringArray(R.array.audio_list);

         listView = (ListView) findViewById(R.id.listView);

         AudioAdapter audioAdapter = new AudioAdapter(this,audioTitels);
         listView.setAdapter(audioAdapter);
         listView.setOnItemClickListener(new
AdapterView.OnItemClickListener() {
             @Override
             public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {

                 switch (i){

                     case  0 :

                         System.out.println("Value of song0 :"+ audioTitels[i]);

                         Toast.makeText(MainActivity.this,"Song to Play",Toast.LENGTH_LONG).show();
                         break;
                     case  1:

                         Toast.makeText(MainActivity.this,"Song to Play",Toast.LENGTH_LONG).show();
                         break;
                     case  2:

                         Toast.makeText(MainActivity.this,"Song to Play",Toast.LENGTH_LONG).show();
                         break;
                     case  3:

                         Toast.makeText(MainActivity.this,"Song to Play",Toast.LENGTH_LONG).show();
                         break;
                     case  4:

                         Toast.makeText(MainActivity.this,"Song to Play",Toast.LENGTH_LONG).show();
                         break;
                     case  5:

                         Toast.makeText(MainActivity.this,"Song to Play",Toast.LENGTH_LONG).show();
                         break;
                     case  6:

                         Toast.makeText(MainActivity.this,"Song to Play",Toast.LENGTH_LONG).show();
                         break;
                     case  7:

                         Toast.makeText(MainActivity.this,"Song to Play",Toast.LENGTH_LONG).show();
                         break;
                     case  8:

                         Toast.makeText(MainActivity.this,"Song to Play",Toast.LENGTH_LONG).show();
                         break;
                     case  9:

                         Toast.makeText(MainActivity.this,"Song to Play",Toast.LENGTH_LONG).show();
                         break;
                     case  10:

                         Toast.makeText(MainActivity.this,"Song to Play",Toast.LENGTH_LONG).show();
                         break;
                     case  11:

                         Toast.makeText(MainActivity.this,"Song to Play",Toast.LENGTH_LONG).show();
                         break;
                     case  12:

                         Toast.makeText(MainActivity.this,"Song to Play",Toast.LENGTH_LONG).show();
                         break;
                     case  13:

                         Toast.makeText(MainActivity.this,"Song to Play",Toast.LENGTH_LONG).show();
                         break;
                     case  14:

                         Toast.makeText(MainActivity.this,"Song to Play",Toast.LENGTH_LONG).show();
                         break;
                     case  15:

                         Toast.makeText(MainActivity.this,"Song to Play",Toast.LENGTH_LONG).show();
                         break;
                     case  16:

                         Toast.makeText(MainActivity.this,"Song to Play",Toast.LENGTH_LONG).show();
                         break;
                     case  17:

                         Toast.makeText(MainActivity.this,"Song to Play",Toast.LENGTH_LONG).show();
                         break;
                     case  18:

                         Toast.makeText(MainActivity.this,"Song to Play",Toast.LENGTH_LONG).show();
                         break;
                     case  19:

                         Toast.makeText(MainActivity.this,"Song to Play",Toast.LENGTH_LONG).show();
                         break;
                     case  20:

                         Toast.makeText(MainActivity.this,"Song to Play",Toast.LENGTH_LONG).show();
                         break;
                     case  21:

                         Toast.makeText(MainActivity.this,"Song to Play",Toast.LENGTH_LONG).show();
                         break;
                     case  22:

                         Toast.makeText(MainActivity.this,"Song to Play",Toast.LENGTH_LONG).show();
                         break;
                     case  23:

                         Toast.makeText(MainActivity.this,"Song to Play",Toast.LENGTH_LONG).show();
                         break;
                     case  24:

                         Toast.makeText(MainActivity.this,"Song to Play",Toast.LENGTH_LONG).show();
                         break;
                     case  25:

                         Toast.makeText(MainActivity.this,"Song to Play",Toast.LENGTH_LONG).show();
                         break;
                     case  26:

                         Toast.makeText(MainActivity.this,"Song to Play",Toast.LENGTH_LONG).show();
                         break;
                     case  27:

                         Toast.makeText(MainActivity.this,"Song to Play",Toast.LENGTH_LONG).show();
                         break;
                     case  28:

                         Toast.makeText(MainActivity.this,"Song to Play",Toast.LENGTH_LONG).show();
                         break;
                     case  29:

                         Toast.makeText(MainActivity.this,"Song to Play",Toast.LENGTH_LONG).show();
                         break;
                     case  30:

                         Toast.makeText(MainActivity.this,"Song to Play",Toast.LENGTH_LONG).show();
                         break;
                     case  31:

                         Toast.makeText(MainActivity.this,"Song to Play",Toast.LENGTH_LONG).show();
                         break;
                     case  32:

                         Toast.makeText(MainActivity.this,"Song to Play",Toast.LENGTH_LONG).show();
                         break;
                     case  33:

                         Toast.makeText(MainActivity.this,"Song to Play",Toast.LENGTH_LONG).show();
                         break;
                     case  34:

                         Toast.makeText(MainActivity.this,"Song to Play",Toast.LENGTH_LONG).show();
                         break;
                     case  35:

                         Toast.makeText(MainActivity.this,"Song to Play",Toast.LENGTH_LONG).show();
                         break;
                     case  36:

                         Toast.makeText(MainActivity.this,"Song to Play",Toast.LENGTH_LONG).show();
                         break;
                     case  37:

                         Toast.makeText(MainActivity.this,"Song to Play",Toast.LENGTH_LONG).show();
                         break;
                     case  38:

                         Toast.makeText(MainActivity.this,"Song to Play",Toast.LENGTH_LONG).show();
                         break;
                     case  39:

                         Toast.makeText(MainActivity.this,"Song to Play",Toast.LENGTH_LONG).show();
                         break;
                     case  40:

                         Toast.makeText(MainActivity.this,"Song to Play",Toast.LENGTH_LONG).show();
                         break;

                     case  41:

                         Toast.makeText(MainActivity.this,"Song to Play",Toast.LENGTH_LONG).show();
                         break;
                     case  42:

                         Toast.makeText(MainActivity.this,"Song to Play",Toast.LENGTH_LONG).show();
                         break;
                     case  43:

                         Toast.makeText(MainActivity.this,"Song to Play",Toast.LENGTH_LONG).show();
                         break;
                     case  44:

                         Toast.makeText(MainActivity.this,"Song to Play",Toast.LENGTH_LONG).show();
                         break;
                     case  45:

                         Toast.makeText(MainActivity.this,"Song to Play",Toast.LENGTH_LONG).show();
                         break;
                     case  46:

                         Toast.makeText(MainActivity.this,"Song to Play",Toast.LENGTH_LONG).show();
                         break;
                     case  47:

                         Toast.makeText(MainActivity.this,"Song to Play",Toast.LENGTH_LONG).show();
                         break;
                     case  48:

                         Toast.makeText(MainActivity.this,"Song to Play",Toast.LENGTH_LONG).show();
                         break;
                     case  49:

                         Toast.makeText(MainActivity.this,"Song to Play",Toast.LENGTH_LONG).show();
                         break;
                     case  50:

                         Toast.makeText(MainActivity.this,"Song to Play",Toast.LENGTH_LONG).show();
                         break;
                     case  51:

                         Toast.makeText(MainActivity.this,"Song to Play",Toast.LENGTH_LONG).show();
                         break;
                     case  52:

                         Toast.makeText(MainActivity.this,"Song to Play",Toast.LENGTH_LONG).show();
                         break;
                     case  53:

                         Toast.makeText(MainActivity.this,"Song to Play",Toast.LENGTH_LONG).show();
                         break;
                     case  54:

                         Toast.makeText(MainActivity.this,"Song to Play",Toast.LENGTH_LONG).show();
                         break;
                     case  55:

                         Toast.makeText(MainActivity.this,"Song to Play",Toast.LENGTH_LONG).show();
                         break;
                     case  56:

                         Toast.makeText(MainActivity.this,"Song to Play",Toast.LENGTH_LONG).show();
                         break;
                     case  57:

                         Toast.makeText(MainActivity.this,"Song to Play",Toast.LENGTH_LONG).show();
                         break;
                     case  58:

                         Toast.makeText(MainActivity.this,"Song to Play",Toast.LENGTH_LONG).show();
                         break;
                     case  59:

                         Toast.makeText(MainActivity.this,"Song to Play",Toast.LENGTH_LONG).show();
                         break;
                     case  60:

                         Toast.makeText(MainActivity.this,"Song to Play",Toast.LENGTH_LONG).show();
                         break;
                     case  61:

                         Toast.makeText(MainActivity.this,"Song to Play",Toast.LENGTH_LONG).show();
                         break;
                     case  62:

                         Toast.makeText(MainActivity.this,"Song to Play",Toast.LENGTH_LONG).show();
                         break;
                     case  63:

                         Toast.makeText(MainActivity.this,"Song to Play",Toast.LENGTH_LONG).show();
                         break;
                     case  64:

                         Toast.makeText(MainActivity.this,"Song to Play",Toast.LENGTH_LONG).show();
                         break;
                     case  65:

                         Toast.makeText(MainActivity.this,"Song to Play",Toast.LENGTH_LONG).show();
                         break;
                     case  66:

                         Toast.makeText(MainActivity.this,"Song to Play",Toast.LENGTH_LONG).show();
                         break;
                     case  67:

                         Toast.makeText(MainActivity.this,"Song to Play",Toast.LENGTH_LONG).show();
                         break;
                     case  68:

                         Toast.makeText(MainActivity.this,"Song to Play",Toast.LENGTH_LONG).show();
                         break;
                     case  69:

                         Toast.makeText(MainActivity.this,"Song to Play",Toast.LENGTH_LONG).show();
                         break;
                     case  70:

                         Toast.makeText(MainActivity.this,"Song to Play",Toast.LENGTH_LONG).show();
                         break;
                     case  71:

                         Toast.makeText(MainActivity.this,"Song to Play",Toast.LENGTH_LONG).show();
                         break;
                     case  72:

                         Toast.makeText(MainActivity.this,"Song to Play",Toast.LENGTH_LONG).show();
                         break;
                     case  73:

                         Toast.makeText(MainActivity.this,"Song to Play",Toast.LENGTH_LONG).show();
                         break;
                     case  74:

                         Toast.makeText(MainActivity.this,"Song to Play",Toast.LENGTH_LONG).show();
                         break;
                     case  75:

                         Toast.makeText(MainActivity.this,"Song to Play",Toast.LENGTH_LONG).show();
                         break;
                     case  76:

                         Toast.makeText(MainActivity.this,"Song to Play",Toast.LENGTH_LONG).show();
                         break;
                     case  77:

                         Toast.makeText(MainActivity.this,"Song to Play",Toast.LENGTH_LONG).show();
                         break;
                     case  78:

                         Toast.makeText(MainActivity.this,"Song to Play",Toast.LENGTH_LONG).show();
                         break;
                     case  79:

                         Toast.makeText(MainActivity.this,"Song to Play",Toast.LENGTH_LONG).show();
                         break;
                     case  80:

                         Toast.makeText(MainActivity.this,"Song to Play",Toast.LENGTH_LONG).show();
                         break;
                     case  81:

                         Toast.makeText(MainActivity.this,"Song to Play",Toast.LENGTH_LONG).show();
                         break;
                     case  82:

                         Toast.makeText(MainActivity.this,"Song to Play",Toast.LENGTH_LONG).show();
                         break;
                     case  83:

                         Toast.makeText(MainActivity.this,"Song to Play",Toast.LENGTH_LONG).show();
                         break;
                     case  84:

                         Toast.makeText(MainActivity.this,"Song to Play",Toast.LENGTH_LONG).show();
                         break;
                     case  85:

                         Toast.makeText(MainActivity.this,"Song to Play",Toast.LENGTH_LONG).show();
                         break;
                     case  86:

                         Toast.makeText(MainActivity.this,"Song to Play",Toast.LENGTH_LONG).show();
                         break;
                     case  87:

                         Toast.makeText(MainActivity.this,"Song to Play",Toast.LENGTH_LONG).show();
                         break;
                     case  88:

                         Toast.makeText(MainActivity.this,"Song to Play",Toast.LENGTH_LONG).show();
                         break;
                     case  89:

                         Toast.makeText(MainActivity.this,"Song to Play",Toast.LENGTH_LONG).show();
                         break;
                     case  90:

                         Toast.makeText(MainActivity.this,"Song to Play",Toast.LENGTH_LONG).show();
                         break;
                     case  91:

                         Toast.makeText(MainActivity.this,"Song to Play",Toast.LENGTH_LONG).show();
                         break;
                     case  92:

                         Toast.makeText(MainActivity.this,"Song to Play",Toast.LENGTH_LONG).show();
                         break;
                     case  93:

                         Toast.makeText(MainActivity.this,"Song to Play",Toast.LENGTH_LONG).show();
                         break;
                     case  94:

                         Toast.makeText(MainActivity.this,"Song to Play",Toast.LENGTH_LONG).show();
                         break;
                     case  95:

                         Toast.makeText(MainActivity.this,"Song to Play",Toast.LENGTH_LONG).show();
                         break;
                     case  96:

                         Toast.makeText(MainActivity.this,"Song to Play",Toast.LENGTH_LONG).show();
                         break;
                     case  97:

                         Toast.makeText(MainActivity.this,"Song to Play",Toast.LENGTH_LONG).show();
                         break;
                     case  98:

                         Toast.makeText(MainActivity.this,"Song to Play",Toast.LENGTH_LONG).show();
                         break;
                     case  99:

                         Toast.makeText(MainActivity.this,"Song to Play",Toast.LENGTH_LONG).show();
                         break;
                     case  100:
                         System.out.println("Value of song100 :"+ audioTitels[i]);

                         Toast.makeText(MainActivity.this,"Song to Play",Toast.LENGTH_LONG).show();
                         break;
                     case  101:

                         Toast.makeText(MainActivity.this,"Song to Play",Toast.LENGTH_LONG).show();
                         break;
                     case  102:

                         Toast.makeText(MainActivity.this,"Song to Play",Toast.LENGTH_LONG).show();
                         break;
                     case  103:

                         Toast.makeText(MainActivity.this,"Song to Play",Toast.LENGTH_LONG).show();
                         break;
                     case  104:

                         Toast.makeText(MainActivity.this,"Song to Play",Toast.LENGTH_LONG).show();
                         break;
                     case  105:

                         Toast.makeText(MainActivity.this,"Song to Play",Toast.LENGTH_LONG).show();
                         break;
                     case  106:

                         Toast.makeText(MainActivity.this,"Song to Play",Toast.LENGTH_LONG).show();
                         break;
                     case  107:

                         Toast.makeText(MainActivity.this,"Song to Play",Toast.LENGTH_LONG).show();
                         break;
                     case  108:

                         Toast.makeText(MainActivity.this,"Song to Play",Toast.LENGTH_LONG).show();
                         break;
                     case  109:

                         Toast.makeText(MainActivity.this,"Song to Play",Toast.LENGTH_LONG).show();
                         break;
                     case  110:

                         Toast.makeText(MainActivity.this,"Song to Play",Toast.LENGTH_LONG).show();
                         break;
                     case  111:

                         Toast.makeText(MainActivity.this,"Song to Play",Toast.LENGTH_LONG).show();
                         break;
                     case  112:

                         Toast.makeText(MainActivity.this,"Song to Play",Toast.LENGTH_LONG).show();
                         break;
                     case  113:
                         System.out.println("Value of song113 :"+ audioTitels[i]);

                         Toast.makeText(MainActivity.this,"Song to Play",Toast.LENGTH_LONG).show();
                         break;

    }
}
             });
     }

     class AudioAdapter extends ArrayAdapter<String>{

         Context context;
         String[] myTitles;

         AudioAdapter(Context c,String[] titles){

         super(c,R.layout.single_audio,R.id.audioText,titles);

             this.context = c;
             this.myTitles = titles;

         }

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

             View row = convertView;
             if(row == null){

                 LayoutInflater layoutInflater = (LayoutInflater)
context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
                 row =
layoutInflater.inflate(R.layout.single_audio,parent,false);

             }

             //getting refernce to the textview
             TextView myTitle = (TextView)
row.findViewById(R.id.audioText);

             myTitle.setText(myTitles[position]);

myTitle.setAnimation(AnimationUtils.loadAnimation(context,R.anim.list_animation));

             return row;
         }
     }

}
```

<p>activity_main.xml:</p>

```<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
     xmlns:app="http://schemas.android.com/apk/res-auto"
     xmlns:tools="http://schemas.android.com/tools"
     android:layout_width="match_parent"
     android:layout_height="match_parent"
     android:orientation="vertical"
     tools:context="com.xyz.listviewaudio.MainActivity"
     android:weightSum="1">

   <ListView
       android:id="@+id/listView"
       android:layout_width="wrap_content"
       android:layout_height="430dp"
       android:layout_alignParentTop="true"
       android:layout_alignParentLeft="true"
       android:layout_alignParentStart="true"
       android:layout_weight="0.88">

   </ListView>
</LinearLayout>
```

<p>single_audio.xml:</p>

```<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
     android:orientation="vertical" android:layout_width="match_parent"
     android:layout_height="match_parent">

     <TextView
         android:layout_width="match_parent"
         android:layout_height="wrap_content"
         android:layout_marginLeft="16dp"
         android:layout_marginTop="16dp"
         android:textAlignment="gravity"
         android:layout_marginBottom="16dp"
         android:id="@+id/audioText"/>

</RelativeLayout>
```

答:
You can perform click event in getView like this,</p>

```<code>      @Override
                 public View getView(int position, View convertView, ViewGroup
        parent) {

                     View row = convertView;
                     if(row == null){

                         LayoutInflater layoutInflater = (LayoutInflater)
        context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
                         row =
        layoutInflater.inflate(R.layout.single_audio,parent,false);

                     }

                     //getting refernce to the textview
                     TextView myTitle = (TextView)
        row.findViewById(R.id.audioText);

                     myTitle.setText(myTitles[position]);

        myTitle.setAnimation(AnimationUtils.loadAnimation(context,R.anim.list_animation));

// ========= Permform Click Event ===================
    row.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    v.setTag((position+1)+".mp3");
                    // You can do your code here ....
                }
            });

                     return row;
                 }
</code>```

Body:
I created a MainActivity that holds the list of player names.When I click to that list_item need to  setTag() method for each of the clicked item and that should call the SubActivity.In SubActivity how to implement MediaPlayer and how  to get those Tag.

MainActivity :

public class MainActivity extends AppCompatActivity {

     String[] audioTitels;
     ListView listView;

     @Override
     protected void onCreate(Bundle savedInstanceState) {
         super.onCreate(savedInstanceState);
         setContentView(R.layout.activity_main);

         Resources res = getResources();
         audioTitels = res.getStringArray(R.array.audio_list);

         listView = (ListView) findViewById(R.id.listView);

         AudioAdapter audioAdapter = new AudioAdapter(this,audioTitels);
         listView.setAdapter(audioAdapter);
         listView.setOnItemClickListener(new
AdapterView.OnItemClickListener() {
             @Override
             public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {

                 switch (i){

                     case  0 :

                         System.out.println("Value of song0 :"+ audioTitels[i]);

                         Toast.makeText(MainActivity.this,"Song to Play",Toast.LENGTH_LONG).show();
                         break;
                     case  1:

                         Toast.makeText(MainActivity.this,"Song to Play",Toast.LENGTH_LONG).show();
                         break;
                     case  2:

                         Toast.makeText(MainActivity.this,"Song to Play",Toast.LENGTH_LONG).show();
                         break;
                     case  3:

                         Toast.makeText(MainActivity.this,"Song to Play",Toast.LENGTH_LONG).show();
                         break;
                     case  4:

                         Toast.makeText(MainActivity.this,"Song to Play",Toast.LENGTH_LONG).show();
                         break;
                     case  5:

                         Toast.makeText(MainActivity.this,"Song to Play",Toast.LENGTH_LONG).show();
                         break;
                     case  6:

                         Toast.makeText(MainActivity.this,"Song to Play",Toast.LENGTH_LONG).show();
                         break;
                     case  7:

                         Toast.makeText(MainActivity.this,"Song to Play",Toast.LENGTH_LONG).show();
                         break;
                     case  8:

                         Toast.makeText(MainActivity.this,"Song to Play",Toast.LENGTH_LONG).show();
                         break;
                     case  9:

                         Toast.makeText(MainActivity.this,"Song to Play",Toast.LENGTH_LONG).show();
                         break;
                     case  10:

                         Toast.makeText(MainActivity.this,"Song to Play",Toast.LENGTH_LONG).show();
                         break;
                     case  11:

                         Toast.makeText(MainActivity.this,"Song to Play",Toast.LENGTH_LONG).show();
                         break;
                     case  12:

                         Toast.makeText(MainActivity.this,"Song to Play",Toast.LENGTH_LONG).show();
                         break;
                     case  13:

                         Toast.makeText(MainActivity.this,"Song to Play",Toast.LENGTH_LONG).show();
                         break;
                     case  14:

                         Toast.makeText(MainActivity.this,"Song to Play",Toast.LENGTH_LONG).show();
                         break;
                     case  15:

                         Toast.makeText(MainActivity.this,"Song to Play",Toast.LENGTH_LONG).show();
                         break;
                     case  16:

                         Toast.makeText(MainActivity.this,"Song to Play",Toast.LENGTH_LONG).show();
                         break;
                     case  17:

                         Toast.makeText(MainActivity.this,"Song to Play",Toast.LENGTH_LONG).show();
                         break;
                     case  18:

                         Toast.makeText(MainActivity.this,"Song to Play",Toast.LENGTH_LONG).show();
                         break;
                     case  19:

                         Toast.makeText(MainActivity.this,"Song to Play",Toast.LENGTH_LONG).show();
                         break;
                     case  20:

                         Toast.makeText(MainActivity.this,"Song to Play",Toast.LENGTH_LONG).show();
                         break;
                     case  21:

                         Toast.makeText(MainActivity.this,"Song to Play",Toast.LENGTH_LONG).show();
                         break;
                     case  22:

                         Toast.makeText(MainActivity.this,"Song to Play",Toast.LENGTH_LONG).show();
                         break;
                     case  23:

                         Toast.makeText(MainActivity.this,"Song to Play",Toast.LENGTH_LONG).show();
                         break;
                     case  24:

                         Toast.makeText(MainActivity.this,"Song to Play",Toast.LENGTH_LONG).show();
                         break;
                     case  25:

                         Toast.makeText(MainActivity.this,"Song to Play",Toast.LENGTH_LONG).show();
                         break;
                     case  26:

                         Toast.makeText(MainActivity.this,"Song to Play",Toast.LENGTH_LONG).show();
                         break;
                     case  27:

                         Toast.makeText(MainActivity.this,"Song to Play",Toast.LENGTH_LONG).show();
                         break;
                     case  28:

                         Toast.makeText(MainActivity.this,"Song to Play",Toast.LENGTH_LONG).show();
                         break;
                     case  29:

                         Toast.makeText(MainActivity.this,"Song to Play",Toast.LENGTH_LONG).show();
                         break;
                     case  30:

                         Toast.makeText(MainActivity.this,"Song to Play",Toast.LENGTH_LONG).show();
                         break;
                     case  31:

                         Toast.makeText(MainActivity.this,"Song to Play",Toast.LENGTH_LONG).show();
                         break;
                     case  32:

                         Toast.makeText(MainActivity.this,"Song to Play",Toast.LENGTH_LONG).show();
                         break;
                     case  33:

                         Toast.makeText(MainActivity.this,"Song to Play",Toast.LENGTH_LONG).show();
                         break;
                     case  34:

                         Toast.makeText(MainActivity.this,"Song to Play",Toast.LENGTH_LONG).show();
                         break;
                     case  35:

                         Toast.makeText(MainActivity.this,"Song to Play",Toast.LENGTH_LONG).show();
                         break;
                     case  36:

                         Toast.makeText(MainActivity.this,"Song to Play",Toast.LENGTH_LONG).show();
                         break;
                     case  37:

                         Toast.makeText(MainActivity.this,"Song to Play",Toast.LENGTH_LONG).show();
                         break;
                     case  38:

                         Toast.makeText(MainActivity.this,"Song to Play",Toast.LENGTH_LONG).show();
                         break;
                     case  39:

                         Toast.makeText(MainActivity.this,"Song to Play",Toast.LENGTH_LONG).show();
                         break;
                     case  40:

                         Toast.makeText(MainActivity.this,"Song to Play",Toast.LENGTH_LONG).show();
                         break;

                     case  41:

                         Toast.makeText(MainActivity.this,"Song to Play",Toast.LENGTH_LONG).show();
                         break;
                     case  42:

                         Toast.makeText(MainActivity.this,"Song to Play",Toast.LENGTH_LONG).show();
                         break;
                     case  43:

                         Toast.makeText(MainActivity.this,"Song to Play",Toast.LENGTH_LONG).show();
                         break;
                     case  44:

                         Toast.makeText(MainActivity.this,"Song to Play",Toast.LENGTH_LONG).show();
                         break;
                     case  45:

                         Toast.makeText(MainActivity.this,"Song to Play",Toast.LENGTH_LONG).show();
                         break;
                     case  46:

                         Toast.makeText(MainActivity.this,"Song to Play",Toast.LENGTH_LONG).show();
                         break;
                     case  47:

                         Toast.makeText(MainActivity.this,"Song to Play",Toast.LENGTH_LONG).show();
                         break;
                     case  48:

                         Toast.makeText(MainActivity.this,"Song to Play",Toast.LENGTH_LONG).show();
                         break;
                     case  49:

                         Toast.makeText(MainActivity.this,"Song to Play",Toast.LENGTH_LONG).show();
                         break;
                     case  50:

                         Toast.makeText(MainActivity.this,"Song to Play",Toast.LENGTH_LONG).show();
                         break;
                     case  51:

                         Toast.makeText(MainActivity.this,"Song to Play",Toast.LENGTH_LONG).show();
                         break;
                     case  52:

                         Toast.makeText(MainActivity.this,"Song to Play",Toast.LENGTH_LONG).show();
                         break;
                     case  53:

                         Toast.makeText(MainActivity.this,"Song to Play",Toast.LENGTH_LONG).show();
                         break;
                     case  54:

                         Toast.makeText(MainActivity.this,"Song to Play",Toast.LENGTH_LONG).show();
                         break;
                     case  55:

                         Toast.makeText(MainActivity.this,"Song to Play",Toast.LENGTH_LONG).show();
                         break;
                     case  56:

                         Toast.makeText(MainActivity.this,"Song to Play",Toast.LENGTH_LONG).show();
                         break;
                     case  57:

                         Toast.makeText(MainActivity.this,"Song to Play",Toast.LENGTH_LONG).show();
                         break;
                     case  58:

                         Toast.makeText(MainActivity.this,"Song to Play",Toast.LENGTH_LONG).show();
                         break;
                     case  59:

                         Toast.makeText(MainActivity.this,"Song to Play",Toast.LENGTH_LONG).show();
                         break;
                     case  60:

                         Toast.makeText(MainActivity.this,"Song to Play",Toast.LENGTH_LONG).show();
                         break;
                     case  61:

                         Toast.makeText(MainActivity.this,"Song to Play",Toast.LENGTH_LONG).show();
                         break;
                     case  62:

                         Toast.makeText(MainActivity.this,"Song to Play",Toast.LENGTH_LONG).show();
                         break;
                     case  63:

                         Toast.makeText(MainActivity.this,"Song to Play",Toast.LENGTH_LONG).show();
                         break;
                     case  64:

                         Toast.makeText(MainActivity.this,"Song to Play",Toast.LENGTH_LONG).show();
                         break;
                     case  65:

                         Toast.makeText(MainActivity.this,"Song to Play",Toast.LENGTH_LONG).show();
                         break;
                     case  66:

                         Toast.makeText(MainActivity.this,"Song to Play",Toast.LENGTH_LONG).show();
                         break;
                     case  67:

                         Toast.makeText(MainActivity.this,"Song to Play",Toast.LENGTH_LONG).show();
                         break;
                     case  68:

                         Toast.makeText(MainActivity.this,"Song to Play",Toast.LENGTH_LONG).show();
                         break;
                     case  69:

                         Toast.makeText(MainActivity.this,"Song to Play",Toast.LENGTH_LONG).show();
                         break;
                     case  70:

                         Toast.makeText(MainActivity.this,"Song to Play",Toast.LENGTH_LONG).show();
                         break;
                     case  71:

                         Toast.makeText(MainActivity.this,"Song to Play",Toast.LENGTH_LONG).show();
                         break;
                     case  72:

                         Toast.makeText(MainActivity.this,"Song to Play",Toast.LENGTH_LONG).show();
                         break;
                     case  73:

                         Toast.makeText(MainActivity.this,"Song to Play",Toast.LENGTH_LONG).show();
                         break;
                     case  74:

                         Toast.makeText(MainActivity.this,"Song to Play",Toast.LENGTH_LONG).show();
                         break;
                     case  75:

                         Toast.makeText(MainActivity.this,"Song to Play",Toast.LENGTH_LONG).show();
                         break;
                     case  76:

                         Toast.makeText(MainActivity.this,"Song to Play",Toast.LENGTH_LONG).show();
                         break;
                     case  77:

                         Toast.makeText(MainActivity.this,"Song to Play",Toast.LENGTH_LONG).show();
                         break;
                     case  78:

                         Toast.makeText(MainActivity.this,"Song to Play",Toast.LENGTH_LONG).show();
                         break;
                     case  79:

                         Toast.makeText(MainActivity.this,"Song to Play",Toast.LENGTH_LONG).show();
                         break;
                     case  80:

                         Toast.makeText(MainActivity.this,"Song to Play",Toast.LENGTH_LONG).show();
                         break;
                     case  81:

                         Toast.makeText(MainActivity.this,"Song to Play",Toast.LENGTH_LONG).show();
                         break;
                     case  82:

                         Toast.makeText(MainActivity.this,"Song to Play",Toast.LENGTH_LONG).show();
                         break;
                     case  83:

                         Toast.makeText(MainActivity.this,"Song to Play",Toast.LENGTH_LONG).show();
                         break;
                     case  84:

                         Toast.makeText(MainActivity.this,"Song to Play",Toast.LENGTH_LONG).show();
                         break;
                     case  85:

                         Toast.makeText(MainActivity.this,"Song to Play",Toast.LENGTH_LONG).show();
                         break;
                     case  86:

                         Toast.makeText(MainActivity.this,"Song to Play",Toast.LENGTH_LONG).show();
                         break;
                     case  87:

                         Toast.makeText(MainActivity.this,"Song to Play",Toast.LENGTH_LONG).show();
                         break;
                     case  88:

                         Toast.makeText(MainActivity.this,"Song to Play",Toast.LENGTH_LONG).show();
                         break;
                     case  89:

                         Toast.makeText(MainActivity.this,"Song to Play",Toast.LENGTH_LONG).show();
                         break;
                     case  90:

                         Toast.makeText(MainActivity.this,"Song to Play",Toast.LENGTH_LONG).show();
                         break;
                     case  91:

                         Toast.makeText(MainActivity.this,"Song to Play",Toast.LENGTH_LONG).show();
                         break;
                     case  92:

                         Toast.makeText(MainActivity.this,"Song to Play",Toast.LENGTH_LONG).show();
                         break;
                     case  93:

                         Toast.makeText(MainActivity.this,"Song to Play",Toast.LENGTH_LONG).show();
                         break;
                     case  94:

                         Toast.makeText(MainActivity.this,"Song to Play",Toast.LENGTH_LONG).show();
                         break;
                     case  95:

                         Toast.makeText(MainActivity.this,"Song to Play",Toast.LENGTH_LONG).show();
                         break;
                     case  96:

                         Toast.makeText(MainActivity.this,"Song to Play",Toast.LENGTH_LONG).show();
                         break;
                     case  97:

                         Toast.makeText(MainActivity.this,"Song to Play",Toast.LENGTH_LONG).show();
                         break;
                     case  98:

                         Toast.makeText(MainActivity.this,"Song to Play",Toast.LENGTH_LONG).show();
                         break;
                     case  99:

                         Toast.makeText(MainActivity.this,"Song to Play",Toast.LENGTH_LONG).show();
                         break;
                     case  100:
                         System.out.println("Value of song100 :"+ audioTitels[i]);

                         Toast.makeText(MainActivity.this,"Song to Play",Toast.LENGTH_LONG).show();
                         break;
                     case  101:

                         Toast.makeText(MainActivity.this,"Song to Play",Toast.LENGTH_LONG).show();
                         break;
                     case  102:

                         Toast.makeText(MainActivity.this,"Song to Play",Toast.LENGTH_LONG).show();
                         break;
                     case  103:

                         Toast.makeText(MainActivity.this,"Song to Play",Toast.LENGTH_LONG).show();
                         break;
                     case  104:

                         Toast.makeText(MainActivity.this,"Song to Play",Toast.LENGTH_LONG).show();
                         break;
                     case  105:

                         Toast.makeText(MainActivity.this,"Song to Play",Toast.LENGTH_LONG).show();
                         break;
                     case  106:

                         Toast.makeText(MainActivity.this,"Song to Play",Toast.LENGTH_LONG).show();
                         break;
                     case  107:

                         Toast.makeText(MainActivity.this,"Song to Play",Toast.LENGTH_LONG).show();
                         break;
                     case  108:

                         Toast.makeText(MainActivity.this,"Song to Play",Toast.LENGTH_LONG).show();
                         break;
                     case  109:

                         Toast.makeText(MainActivity.this,"Song to Play",Toast.LENGTH_LONG).show();
                         break;
                     case  110:

                         Toast.makeText(MainActivity.this,"Song to Play",Toast.LENGTH_LONG).show();
                         break;
                     case  111:

                         Toast.makeText(MainActivity.this,"Song to Play",Toast.LENGTH_LONG).show();
                         break;
                     case  112:

                         Toast.makeText(MainActivity.this,"Song to Play",Toast.LENGTH_LONG).show();
                         break;
                     case  113:
                         System.out.println("Value of song113 :"+ audioTitels[i]);

                         Toast.makeText(MainActivity.this,"Song to Play",Toast.LENGTH_LONG).show();
                         break;

    }
}
             });
     }

     class AudioAdapter extends ArrayAdapter<String>{

         Context context;
         String[] myTitles;

         AudioAdapter(Context c,String[] titles){

         super(c,R.layout.single_audio,R.id.audioText,titles);

             this.context = c;
             this.myTitles = titles;

         }

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

             View row = convertView;
             if(row == null){

                 LayoutInflater layoutInflater = (LayoutInflater)
context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
                 row =
layoutInflater.inflate(R.layout.single_audio,parent,false);

             }

             //getting refernce to the textview
             TextView myTitle = (TextView)
row.findViewById(R.id.audioText);

             myTitle.setText(myTitles[position]);

myTitle.setAnimation(AnimationUtils.loadAnimation(context,R.anim.list_animation));

             return row;
         }
     }

}

activity_main.xml:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
     xmlns:app="http://schemas.android.com/apk/res-auto"
     xmlns:tools="http://schemas.android.com/tools"
     android:layout_width="match_parent"
     android:layout_height="match_parent"
     android:orientation="vertical"
     tools:context="com.xyz.listviewaudio.MainActivity"
     android:weightSum="1">

   <ListView
       android:id="@+id/listView"
       android:layout_width="wrap_content"
       android:layout_height="430dp"
       android:layout_alignParentTop="true"
       android:layout_alignParentLeft="true"
       android:layout_alignParentStart="true"
       android:layout_weight="0.88">

   </ListView>
</LinearLayout>

single_audio.xml:

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

     <TextView
         android:layout_width="match_parent"
         android:layout_height="wrap_content"
         android:layout_marginLeft="16dp"
         android:layout_marginTop="16dp"
         android:textAlignment="gravity"
         android:layout_marginBottom="16dp"
         android:id="@+id/audioText"/>

</RelativeLayout>

Body:
You can perform click event in getView like this,

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

                     View row = convertView;
                     if(row == null){

                         LayoutInflater layoutInflater = (LayoutInflater)
        context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
                         row =
        layoutInflater.inflate(R.layout.single_audio,parent,false);

                     }

                     //getting refernce to the textview
                     TextView myTitle = (TextView)
        row.findViewById(R.id.audioText);

                     myTitle.setText(myTitles[position]);

        myTitle.setAnimation(AnimationUtils.loadAnimation(context,R.anim.list_animation));

// ========= Permform Click Event ===================
    row.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    v.setTag((position+1)+".mp3");
                    // You can do your code here ....
                }
            });

                     return row;
                 }


来源: stackexchange

问:
:first-of-type is not working
I have the problem, because the :first-of-type margin don't show. I am trying to put left and right margin to be 10px and between elements to be 20px.

Here is the code:

#players {
  width: 960px;
  height: 283px;
  position: relative;
}

.igrac {
  width: 220px;
  margin-right: 20px;
  height: 283px;
  position: relative;
  display: block;
  float: left;
  background-color: #fff;
}

.igrac:first-of-type {
  margin-left: 10px;
}

.igrac:last-of-type {
  margin-right: 10px;
}```
<pre class="snippet-code-html lang-html prettyprint-override"><code><div id="players">
  <div class="naslov_dela">
    <p>IGRAČI</p>
    Svi igrači >>
  </div>
  <div class="clear_fix"></div>
  <div class="igrac">
    <img src="images/players/djordjevicdusan.jpg" />
    <p>Đorđević Dušan</p>
    <p>Tehničar</p>
    <div class="boja"></div>
  </div>
  <div class="igrac">
    <img src="images/players/petrovicpetar.jpg" />
    <p>Petrović Petar</p>
    <p>Korektor</p>
    <div class="boja"></div>
  </div>
  <div class="igrac">
    <img src="images/players/jevticnemanja.jpg" />
    <p>Jevtić Nemanja</p>
    <p>Libero</p>
    <div class="boja"></div>
  </div>
  <div class="igrac">
    <img src="images/players/aleksicmilan.jpg" />
    <p>Aleksić Milan</p>
    <p>Primač</p>
    <div class="boja"></div>
  </div>
</div></code>```

Does anyone knows why this :first-of-type margin does not showing?

答:
you can't access .igrac using :first/last-of-type alone, you will need the help of sibling selectors:

adjacent sibling selector +

general sibling selector ~

#players {
  /*changed to make it responsive*/
  max-width: 960px;
  width: 100%;
  height: 283px;
  position: relative;
}

.igrac {
  /* change width to fit demo view*/
  width: 125px;
  margin-right: 20px;
  height: 283px;
  position: relative;
  float: left;
  background-color: #fff;
  /*no need for display:block - div is already a block level element*/
}

.clear_fix+.igrac,
.naslov_dela~.igrac:last-of-type {
  background: red
}

.clear_fix+.igrac {
  margin-left: 10px
}

.naslov_dela~.igrac:last-of-type {
  margin-right: 10px
}```
<pre class="snippet-code-html lang-html prettyprint-override"><code><div id="players">
  <div class="naslov_dela">
    <p>IGRAČI</p>
    Svi igrači >>
  </div>
  <div class="clear_fix"></div>
  <div class="igrac">
    <img src="images/players/djordjevicdusan.jpg" />
    <p>Đorđević Dušan</p>
    <p>Tehničar</p>
    <div class="boja"></div>
  </div>
  <div class="igrac">
    <img src="images/players/petrovicpetar.jpg" />
    <p>Petrović Petar</p>
    <p>Korektor</p>
    <div class="boja"></div>
  </div>
  <div class="igrac">
    <img src="images/players/jevticnemanja.jpg" />
    <p>Jevtić Nemanja</p>
    <p>Libero</p>
    <div class="boja"></div>
  </div>
  <div class="igrac">
    <img src="images/players/aleksicmilan.jpg" />
    <p>Aleksić Milan</p>
    <p>Primač</p>
    <div class="boja"></div>
  </div>
</div></code>```

ContentLicense: CC BY-SA 3.0

Title: :first-of-type is not working

Body:
I have the problem, because the :first-of-type margin don't show. I am trying to put left and right margin to be 10px and between elements to be 20px.

Here is the code:

#players {
  width: 960px;
  height: 283px;
  position: relative;
}

.igrac {
  width: 220px;
  margin-right: 20px;
  height: 283px;
  position: relative;
  display: block;
  float: left;
  background-color: #fff;
}

.igrac:first-of-type {
  margin-left: 10px;
}

.igrac:last-of-type {
  margin-right: 10px;
}

IGRAČI

    Svi igrači >>

Đorđević Dušan

Tehničar

Petrović Petar

Korektor

Jevtić Nemanja

Libero

Aleksić Milan

Primač

Does anyone knows why this :first-of-type margin does not showing?

Body:
you can't access .igrac using :first/last-of-type alone, you will need the help of sibling selectors:

adjacent sibling selector +

general sibling selector ~

#players {
  /*changed to make it responsive*/
  max-width: 960px;
  width: 100%;
  height: 283px;
  position: relative;
}

.igrac {
  /* change width to fit demo view*/
  width: 125px;
  margin-right: 20px;
  height: 283px;
  position: relative;
  float: left;
  background-color: #fff;
  /*no need for display:block - div is already a block level element*/
}

.clear_fix+.igrac,
.naslov_dela~.igrac:last-of-type {
  background: red
}

.clear_fix+.igrac {
  margin-left: 10px
}

.naslov_dela~.igrac:last-of-type {
  margin-right: 10px
}

<div id="players">
  <div class="naslov_dela">
    <p>IGRAČI</p>
    <a href="#">Svi igrači >></a>
  </div>
  <div class="clear_fix"></div>
  <div class="igrac">
    <img src="images/players/djordjevicdusan.jpg" />
    <p>Đorđević Dušan</p>
    <p>Tehničar</p>
    <div class="boja"></div>
  </div>
  <div class="igrac">
    <img src="images/players/petrovicpetar.jpg" />
    <p>Petrović Petar</p>
    <p>Korektor</p>
    <div class="boja"></div>
  </div>
  <div class="igrac">
    <img src="images/players/jevticnemanja.jpg" />
    <p>Jevtić Nemanja</p>
    <p>Libero</p>
    <div class="boja"></div>
  </div>
  <div class="igrac">
    <img src="images/players/aleksicmilan.jpg" />
    <p>Aleksić Milan</p>
    <p>Primač</p>
    <div class="boja"></div>
  </div>
</div>


问:
Android App Compile Not Generating Package Resources
When attempting to compile my Xamarin.Android app I get the compile error:

Error 3   The file "obj\Debug\android\bin\packaged_resources" does not exist. MyApp.UI.Droid

This error occurred after I made some changes (added some new classes - cannot remember what it was). But I didn't change any project settings, nor go delete actual files in the obj folder.

What is the cause of this error and how can I fix this?

Some information that may be useful:

The project is a Cross-Platform PCL project - Core, Android, and iOS Projects

The project uses MVVM Cross

答: I had the same problem. To solve I had to remove all nuget packages from droid project, and reinstalled xamarin.forms again (has to be same version used in other projects).</p>


问:
Extensible application using Qt
I am working on an application which interact with a database and construct reports, I want this application to be extensible and I can in the future to integrate custom report builders to the application as plugins.

I have some question about the plugin architecture supported by Qt:

Can I load the plugins in there own processes ?

How could I send some custom QML type from the plugin to main application and hook some event handlers on it.

Another question: is there any framework to develop service based qt application ?

答:
Can I load the plugins in there own processes ?

Not with the plugin mechanism (QPluginLoader). The plugin mechanism dynamically loads libraries (different threads are possible). However, your plugins can be a normal application, that gets started by your main application via QProcess, and exchange data via stdin/stdout (or other IPC mechanisms)

How could I send some custom QML type from the plugin to main application and hook some event handlers on it.

In case you use normal plugins, simply add method that returns the created QML object. Have a look at:https://doc.qt.io/qt-5/qtqml-cppintegration-interactqmlfromcpp.html#loading-qml-objects-from-c

In case you want to use the multi process version, it gets slightly more complicated. Pass the QML code via stdout and create it in your main application. Pass some "communicator" object to this created QML object, so that the QML type can send back data via that communicator to it's original process.

Title: Extensible application using Qt


问:
How to change password masking character in Xamarin forms - Entry
I've currently faced a rather simple issue which eventually put me to a dead end. I am building an application that uses Xamarin Forms and want to change a masking character when user enters password from a bullet to an asterisk.

For entering password I'm using Entry control in Portable lib project in my content page (in VS2017 professional):

```<code><Entry x:Name="Entry_Password" Placeholder="Password" IsPassword="True" />
</code>```

I know that I probably should create a custom Renderer in Android project for this one, but would really appreciate how to do it for this specific purpose.

答:
Am sure the converter answer will work , but as a personal preference i dont like it. this looks like a renderer job to me .

and here is how i would do it(example only in android because i dont have ios, but its fairly simple to implement it there)

Usage Xamarin forms

```<code>        <controls:PasswordBox Placeholder="Password"/>
</code>```

The Renderer (Android)

```<code>[assembly: ExportRenderer(typeof(PasswordBox), typeof(PasswordBoxRenderer))]
namespace PasswordAsterisk.Droid.Renderers
{
public class PasswordBoxRenderer : EntryRenderer
{
    protected override void OnElementChanged(ElementChangedEventArgs<Entry> e)
    {
        base.OnElementChanged(e);

        if (Control != null)
        {
            Control.InputType = Android.Text.InputTypes.TextVariationPassword |
                      Android.Text.InputTypes.ClassText;

            Control.TransformationMethod = new HiddenPasswordTransformationMethod();
        }
    }
}
internal class HiddenPasswordTransformationMethod : Android.Text.Method.PasswordTransformationMethod
{
    public override Java.Lang.ICharSequence GetTransformationFormatted(Java.Lang.ICharSequence source, Android.Views.View view)
    {
        return new PasswordCharSequence(source);
    }
}

internal class PasswordCharSequence : Java.Lang.Object, Java.Lang.ICharSequence
{
    private Java.Lang.ICharSequence _source;
    public PasswordCharSequence(Java.Lang.ICharSequence source)
    {
        _source = source;
    }

    public char CharAt(int index)
    {
        return '*';
    }

    public int Length()
    {
        return _source.Length();
    }

    public Java.Lang.ICharSequence SubSequenceFormatted(int start, int end)
    {
        return _source.SubSequenceFormatted(start, end);
    }

    public IEnumerator<char> GetEnumerator()
    {
        return _source.GetEnumerator();
    }

    System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator()
    {
        return _source.GetEnumerator();
    }
}
}
</code>```

full source code example in GitHub

Body:
I've currently faced a rather simple issue which eventually put me to a dead end. I am building an application that uses Xamarin Forms and want to change a masking character when user enters password from a bullet to an asterisk.

For entering password I'm using Entry control in Portable lib project in my content page (in VS2017 professional):

<Entry x:Name="Entry_Password" Placeholder="Password" IsPassword="True" />

I know that I probably should create a custom Renderer in Android project for this one, but would really appreciate how to do it for this specific purpose.

Body:
Am sure the converter answer will work , but as a personal preference i dont like it. this looks like a renderer job to me .

and here is how i would do it(example only in android because i dont have ios, but its fairly simple to implement it there)

Usage Xamarin forms

        <controls:PasswordBox Placeholder="Password"/>

The Renderer (Android)

[assembly: ExportRenderer(typeof(PasswordBox), typeof(PasswordBoxRenderer))]
namespace PasswordAsterisk.Droid.Renderers
{
public class PasswordBoxRenderer : EntryRenderer
{
    protected override void OnElementChanged(ElementChangedEventArgs<Entry> e)
    {
        base.OnElementChanged(e);

        if (Control != null)
        {
            Control.InputType = Android.Text.InputTypes.TextVariationPassword |
                      Android.Text.InputTypes.ClassText;

            Control.TransformationMethod = new HiddenPasswordTransformationMethod();
        }
    }
}
internal class HiddenPasswordTransformationMethod : Android.Text.Method.PasswordTransformationMethod
{
    public override Java.Lang.ICharSequence GetTransformationFormatted(Java.Lang.ICharSequence source, Android.Views.View view)
    {
        return new PasswordCharSequence(source);
    }
}

internal class PasswordCharSequence : Java.Lang.Object, Java.Lang.ICharSequence
{
    private Java.Lang.ICharSequence _source;
    public PasswordCharSequence(Java.Lang.ICharSequence source)
    {
        _source = source;
    }

    public char CharAt(int index)
    {
        return '*';
    }

    public int Length()
    {
        return _source.Length();
    }

    public Java.Lang.ICharSequence SubSequenceFormatted(int start, int end)
    {
        return _source.SubSequenceFormatted(start, end);
    }

    public IEnumerator<char> GetEnumerator()
    {
        return _source.GetEnumerator();
    }

    System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator()
    {
        return _source.GetEnumerator();
    }
}
}

full source code example in GitHub


问:
How do I turn an image into a popup with only text
I'm trying to have a popup show when an image is clicked. All I can find is how to enlarge an image. Below is the code I have but it's not working. I'm not sure which part is wrong... Am I allowed to have a table in the span tag? </p>

```<code>.popup {
margin-top: 10%;
position: relative;
display: inline-block;
cursor: pointer;
-webkit-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
}

.popup .popuptext {
visibility: hidden;
width: 250px;
background-color: #5FACD7;
color: #000000;
text-align: center;
border-radius: 6px;
Padding: 8px 0;
position: absolute;
z-index: 1;
bottom: 125%;
left: 50%;
margin-left: -80px;
</code>```

<p>}</p>

```<code>.popup .popuptext::after {
content: "";
position: absolute;
top: 100%;
left: 50%;
margin-left: -5px;
border-width: 5px;
border-style: solid;
border-color: #555 transparent transparent transparent;
}

.popup .show {
visibility: visible;
-webkit-animation: fadeIn 1s;
animation: fadeIn 1s;
}

@-websit-keyframes fadeIn {
from {opacity: 0;}
to {opacity: 1;}
}

@keyframes fadeIn {
from {opacity: 0;}
to {opacity: 1;}
}

<div class="popup" onclick="popup1()">
<img src="../media/hours.jpg" alt="Hours of Operation" width="300"
height="200"/>
<span class="popuptext" id="myPopup">
    <table>
    <tr>
    <th>Day</th>
    <th>Times</th>
    </tr>
    <tr>
        <td> Monday - Wednesday</td>
        <td> Thursday</td>
        <td>Friday</td>
        <td>Saturday/Sunday</td>
    </tr>
    <tr>
        <td>9:00 a.m. - 6:00 p.m.</td>
        <td>9:00 a.m. - 9:00 p.m.</td>
        <td>9:00 a.m. - 8:00 p.m.</td>
        <td>10:00 a.m. - 6:00 p.m.</td>
    </tr>
    </table>
    </span>
</div>

<div class="popup" onClick="=popup2()">
<img src="../media/tickets.jpeg" alt="General Admission" width="300"
height="200"/>
<span class="popuptext" id="myPopup2">
<table>
    <tr>
    <th></th>
    <th>Prices</th>
    </tr>
    <tr>
        <td>Adults: </td>
        <td>Children (5-12): </td>
        <td>Seniors/Students with ID: </td>
        <td>Adult Members: </td>
        <td>Child Members: </td>
    </tr>
    <tr>
        <td>$12.00</td>
        <td>$6.00</td>
        <td>$8.00</td>
        <td>Free</td>
        <td>Free</td>
    </tr>
    </table>
    </span>
</div>
</code>```

答:
You can do this by: http://www.jacklmoore.com/colorbox/
See Demo: http://www.jacklmoore.com/colorbox/example1/
See: Inline HTML</p>

Body:
I'm trying to have a popup show when an image is clicked. All I can find is how to enlarge an image. Below is the code I have but it's not working. I'm not sure which part is wrong... Am I allowed to have a table in the span tag?

.popup {
margin-top: 10%;
position: relative;
display: inline-block;
cursor: pointer;
-webkit-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
}

.popup .popuptext {
visibility: hidden;
width: 250px;
background-color: #5FACD7;
color: #000000;
text-align: center;
border-radius: 6px;
Padding: 8px 0;
position: absolute;
z-index: 1;
bottom: 125%;
left: 50%;
margin-left: -80px;

}

.popup .popuptext::after {
content: "";
position: absolute;
top: 100%;
left: 50%;
margin-left: -5px;
border-width: 5px;
border-style: solid;
border-color: #555 transparent transparent transparent;
}

.popup .show {
visibility: visible;
-webkit-animation: fadeIn 1s;
animation: fadeIn 1s;
}

@-websit-keyframes fadeIn {
from {opacity: 0;}
to {opacity: 1;}
}

@keyframes fadeIn {
from {opacity: 0;}
to {opacity: 1;}
}

    Day
    Times

         Monday - Wednesday
         Thursday
        Friday
        Saturday/Sunday

        9:00 a.m. - 6:00 p.m.
        9:00 a.m. - 9:00 p.m.
        9:00 a.m. - 8:00 p.m.
        10:00 a.m. - 6:00 p.m.

    Prices

        Adults:
        Children (5-12):
        Seniors/Students with ID:
        Adult Members:
        Child Members:

        $12.00
        $6.00
        $8.00
        Free
        Free


问:
Method generalization in Scala
I tried to generalize a method to provide a type safe API as follows:

```<code>abstract class AbstractCommand {
  type T = this.type
  def shuffler(s: T => Seq[AbstractCommand])
}

class TestCommand extends AbstractCommand {
  override def shuffler(s: (TestCommand) => Seq[AbstractCommand]): Unit = ??? //error
}
</code>```

I wanted the expected type of the function argument to be the most specific in this hierarchy. But it didn't work.

Is there a way to do something like that in Scala without introducing some helper type parameters?

答:
You could avoid defining T in the abstract class :

```<code>abstract class AbstractCommand {
  type T
  def shuffler(s: T => Seq[AbstractCommand])
}

class TestCommand extends AbstractCommand {
  type T = TestCommand
  override def shuffler(s: (TestCommand) => Seq[AbstractCommand]): Unit = ??? //compiles !
}
</code>```

On the downside, it's a bit more verbose, on the upside, it's even more generic !

Title: Method generalization in Scala

Body:
I tried to generalize a method to provide a type safe API as follows:

abstract class AbstractCommand {
  type T = this.type
  def shuffler(s: T => Seq[AbstractCommand])
}

class TestCommand extends AbstractCommand {
  override def shuffler(s: (TestCommand) => Seq[AbstractCommand]): Unit = ??? //error
}

I wanted the expected type of the function argument to be the most specific in this hierarchy. But it didn't work.

Is there a way to do something like that in Scala without introducing some helper type parameters?

Body:
You could avoid defining T in the abstract class :

abstract class AbstractCommand {
  type T
  def shuffler(s: T => Seq[AbstractCommand])
}

class TestCommand extends AbstractCommand {
  type T = TestCommand
  override def shuffler(s: (TestCommand) => Seq[AbstractCommand]): Unit = ??? //compiles !
}

On the downside, it's a bit more verbose, on the upside, it's even more generic !


问:
text with input in one row
I have div with input field and text

Here is code

.form-control {
    display: block;
    width: 100%;
    height: 34px;
    position: relative;
    padding: 6px 12px;
    font-size: 14px;
    line-height: 1.42857143;
    color: #555;
    margin: 0 auto;
    background-color: #fff;
    border-color: #1f66b4;
    border-style: solid;
    border-width: 3px;
    background-image: none;
    border-radius: 4px;
    -webkit-box-shadow: inset 0 1px 1px rgba(0, 0, 0, .075);
    box-shadow: inset 0 1px 1px rgba(0, 0, 0, .075);
    -webkit-transition: border-color ease-in-out .15s, -webkit-box-shadow ease-in-out .15s;
    -o-transition: border-color ease-in-out .15s, box-shadow ease-in-out .15s;
    transition: border-color ease-in-out .15s, box-shadow ease-in-out .15s;
}```
<pre class="snippet-code-html lang-html prettyprint-override"><code><div style="width:50%;height:100%;float: left;padding-left:20%">
            <form style="text-align:center;">
                <b>dfsdfsdfsdf</b>
                <input type="text" class="form-control" id="lname" name="lname" placeholder="Last Name" style="margin: 30px auto 0;border-radius:50px;border-width: 1px;">
            </form>
        </div></code>```

But text is over input.

I need to make text in one row with input.
How I can do this?

答:
Hope what you already have works fine. Check it out by running the snippet below.

        <form style="text-align:center;">
            dfsdfsdfsdf
            <input type="text" class="form-control" id="lname" name="lname" placeholder="Last Name" style="margin: 30px auto 0;border-radius:50px;border-width: 1px;">
        </form>

```

Title: text with input in one row

Body:
I have div with input field and text

Here is code

.form-control {
    display: block;
    width: 100%;
    height: 34px;
    position: relative;
    padding: 6px 12px;
    font-size: 14px;
    line-height: 1.42857143;
    color: #555;
    margin: 0 auto;
    background-color: #fff;
    border-color: #1f66b4;
    border-style: solid;
    border-width: 3px;
    background-image: none;
    border-radius: 4px;
    -webkit-box-shadow: inset 0 1px 1px rgba(0, 0, 0, .075);
    box-shadow: inset 0 1px 1px rgba(0, 0, 0, .075);
    -webkit-transition: border-color ease-in-out .15s, -webkit-box-shadow ease-in-out .15s;
    -o-transition: border-color ease-in-out .15s, box-shadow ease-in-out .15s;
    transition: border-color ease-in-out .15s, box-shadow ease-in-out .15s;
}

            <form style="text-align:center;">
                dfsdfsdfsdf
                <input type="text" class="form-control" id="lname" name="lname" placeholder="Last Name" style="margin: 30px auto 0;border-radius:50px;border-width: 1px;">
            </form>

But text is over input.

I need to make text in one row with input.
How I can do this?

Body:
Hope what you already have works fine. Check it out by running the snippet below.

<div style="width:50%;height:100%;float: left;padding-left:20%">
        <form style="text-align:center;">
            <b>dfsdfsdfsdf</b>
            <input type="text" class="form-control" id="lname" name="lname" placeholder="Last Name" style="margin: 30px auto 0;border-radius:50px;border-width: 1px;">
        </form>
    </div>


问:
Get the names of data frames from a list
Say I have the following:

```<code>df1 <- data.frame()
df2 <- data.frame()
mylist = list(df1, df2)
</code>```

Is there a function that will return me the names of these two data frames, i.e. returns me 'df1' 'df2'? I know that names(mylist) will just return me NULL.

答:
```<code>mylist <- list()
mylist[["df1"]] <-df1
mylist[["df2"]] <-df2
names(mylist)
</code>```

or

```<code>mylist[[deparse(substitute(df1))]] <-df1
</code>```

Body:
Say I have the following:

df1 <- data.frame()
df2 <- data.frame()
mylist = list(df1, df2)

Is there a function that will return me the names of these two data frames, i.e. returns me 'df1' 'df2'? I know that names(mylist) will just return me NULL.

Body:
mylist <- list()
mylist[["df1"]] <-df1
mylist[["df2"]] <-df2
names(mylist)

or

mylist[[deparse(substitute(df1))]] <-df1


问:
How to write http url based web service in netbeans?
How can I write a web service where I can query in the URL with some parameters and display the result in the JSON format.

For example, There is a table AppInfo in my database which has two columns named AppID and Status

Now, what I want is to write a web service like that

```<code>http://10.11.201.84?q=Select+*+from+AppInfo+where+AppID='21212'&format=json
</code>```

So, from a user, I will take the application id and get the status using this web service. I might have to use get method for using the HTTP URL request.

Which web service I have to use in this case and how?

答:
I think you're looking for REST web service instead of SOAP web service.

You should take a look to this documentation : Building a RESTful Web Service

Body:
How can I write a web service where I can query in the URL with some parameters and display the result in the JSON format.

For example, There is a table AppInfo in my database which has two columns named AppID and Status

Now, what I want is to write a web service like that

http://10.11.201.84?q=Select+*+from+AppInfo+where+AppID='21212'&format=json

So, from a user, I will take the application id and get the status using this web service. I might have to use get method for using the HTTP URL request.

Which web service I have to use in this case and how?


问:
Laravel collective form and foreach loop
I want to connect my dropdown select form with database, currentli I have sth like this:

```<code>                 @foreach( $clients as $client)
                    {!! Form::select('connected_with',
                     ['name' => $client->name . $client->surname
                      ]) !!}
                    @endforeach
</code>```

And this is my controller:

```<code>        $clients = Client::all();

        return view('report_create')->with('clients', $clients);
</code>```

and i get much fields. I want only one with items from db. How to do it?

答:
If you want to create select list of clients, use pluck():

```<code>$clients = Client::pluck('full_name', 'id');
return view('report_create')->with('clients', $clients);
</code>```

To make it work, you'll also need to define an accessor in the Client model:

```<code>public function getFullNameAttribute()
{
    return $this->name.' '.$this->surname;
}
</code>```

Then just create the list:

```<code>{!! Form::select('connected_with', $clients) !!}
</code>```

Body:
I want to connect my dropdown select form with database, currentli I have sth like this:

                 @foreach( $clients as $client)
                    {!! Form::select('connected_with',
                     ['name' => $client->name . $client->surname
                      ]) !!}
                    @endforeach

And this is my controller:

        $clients = Client::all();

        return view('report_create')->with('clients', $clients);

and i get much fields. I want only one with items from db. How to do it?

Body:
If you want to create select list of clients, use pluck():

$clients = Client::pluck('full_name', 'id');
return view('report_create')->with('clients', $clients);

To make it work, you'll also need to define an accessor in the Client model:

public function getFullNameAttribute()
{
    return $this->name.' '.$this->surname;
}

Then just create the list:

{!! Form::select('connected_with', $clients) !!}


问:
Getting error /api/Questions/ 404 (Not Found)
I'm new to Asp.net combined with Javascript and I can't figure out what to put inside 'url' to get the data from my controller (from entity framework database I created). I keep getting the Error alert because getting data doesn't succeed.

My controller (Controllers/Api/QuestionsController)

```<code>namespace Pasapalabra.Controllers.Api
{
    public class QuestionsController : ApiController
    {
        private PasapalabraContext db = new PasapalabraContext();

        // GET: api/Questions
        public IList<Question> GetQuestions()
        {
            var questions = db.Questions.ToList();
            return questions;
        }

        // GET: api/Questions/5
        [ResponseType(typeof(Question))]
        public IHttpActionResult GetQuestionById(int id)
        {
            Question question = db.Questions.Find(id);
            if (question == null)
            {
                return NotFound();
            }

            return Ok(question);
        }
    }
}
</code>```

My View (Views/Questions/Index.cshtml)

```<code>        function keepPlaying() {
            var questions = getQuestions();
            if (questions.length !== 0) {
                getRandomQuestion('A');
            } else {
                gameOver();
            }
        }

        function getQuestions() {
            $.ajax({
                url: '/api/Questions/',
                type: 'GET',
                dataType: 'json',
                success: function (data) {
                    return data;
                },
                error: function (error) {
                    alert("Error");
                }
            });
        }
</code>```

答:
Please change your ajax call as below;

```<code>function getQuestions(callback) {
        $.ajax({
            url: '/Questions/GetQuestions',
            type: 'GET',
            dataType: 'json',
            success: function (data) {
                callback(data);
            },
            error: function (error) {
                alert("Error");
            }
        });
    }
</code>```

Second part of the problem is you cannot return from an async call like that;

```<code>function keepPlaying() {
        getQuestions(function(questions){
        if (questions.length !== 0) {
            getRandomQuestion('A');
        } else {
            gameOver();
        }
      });
    }
</code>```

Body:
I'm new to Asp.net combined with Javascript and I can't figure out what to put inside 'url' to get the data from my controller (from entity framework database I created). I keep getting the Error alert because getting data doesn't succeed.

My controller (Controllers/Api/QuestionsController)

namespace Pasapalabra.Controllers.Api
{
    public class QuestionsController : ApiController
    {
        private PasapalabraContext db = new PasapalabraContext();

        // GET: api/Questions
        public IList<Question> GetQuestions()
        {
            var questions = db.Questions.ToList();
            return questions;
        }

        // GET: api/Questions/5
        [ResponseType(typeof(Question))]
        public IHttpActionResult GetQuestionById(int id)
        {
            Question question = db.Questions.Find(id);
            if (question == null)
            {
                return NotFound();
            }

            return Ok(question);
        }
    }
}

My View (Views/Questions/Index.cshtml)

        function keepPlaying() {
            var questions = getQuestions();
            if (questions.length !== 0) {
                getRandomQuestion('A');
            } else {
                gameOver();
            }
        }

        function getQuestions() {
            $.ajax({
                url: '/api/Questions/',
                type: 'GET',
                dataType: 'json',
                success: function (data) {
                    return data;
                },
                error: function (error) {
                    alert("Error");
                }
            });
        }

Body:
Please change your ajax call as below;

function getQuestions(callback) {
        $.ajax({
            url: '/Questions/GetQuestions',
            type: 'GET',
            dataType: 'json',
            success: function (data) {
                callback(data);
            },
            error: function (error) {
                alert("Error");
            }
        });
    }

Second part of the problem is you cannot return from an async call like that;

function keepPlaying() {
        getQuestions(function(questions){
        if (questions.length !== 0) {
            getRandomQuestion('A');
        } else {
            gameOver();
        }
      });
    }


问:
java selenium phantomjs can't locate element by xpath
The submitted code was written only for the proof of concept of usage PhantomJS with Selenium.

I'm testing a Single Page Application.

Code works fine with GoogleChrome and FireFox, but can't find element with PhantomJS.

The problem is that driver finds "Login" button on Landing page (by xpath) BUT throws a TimeoutException:ExpectedCondition failed after trying to locate element by xpath when user was redirected on Login form.

I'm using:

Selenium 3.4.0

PhantomJS 2.1.1

My Code:

```<code>public class GoogleSearchTest
{

private WebDriver driver;
private WebDriverWait wait;

@Before
public void SetUp()
{
    System.setProperty("phantomjs.binary.path", "./src/test/resources/drivers/phantomjs.exe");
    driver = new PhantomJSDriver();
    driver.manage().window().maximize();
    driver.get("https://dev.investmentpunk.academy");
    wait = new WebDriverWait(driver, 10);
}
@Test
public void testGoogleSearch() throws InterruptedException
{
    WebElement Login_btn = driver.findElement(By.xpath("//ul/li[@class='ng-scope'][1]"));
    Login_btn.click();

    wait.until(ExpectedConditions.elementToBeClickable(By.xpath("//input[@class='c-input-db ng-pristine ng-untouched ng-empty ng-invalid ng-invalid-required ng-valid-minlength ng-valid-maxlength']"))).sendKeys("user1");

    WebElement Password = driver.findElement(By.xpath("//div[@class='form-row'][2]/input[@class='c-input-db ng-pristine ng-untouched ng-empty ng-invalid ng-invalid-required']"));
    Password.sendKeys("qwerty");

    WebElement Login = driver.findElement(By.xpath("//button[@class='btn btn-blue']"));
    Login.click();
}

@After
public void tearDown()
{
    driver.quit();
}
</code>```

Please, help me to solve this issue.

======================Edited part======================

So, the case is that I'm running the code with TestNG (or with JUnit), using Your xpathes and it worked, until yesterday. So, driver is unable to locate a WebElement Login_btn = driver.findElement(By.xpath("//ul/li[@class='ng-scope']/a[text()='EINLOGGEN']")); I didn't provide any sugnificant changes in the code:

```<code>public class GoogleSearchTest
{
private WebDriver driver;
private WebDriverWait wait;

//second commit mess

@BeforeTest
public void SetUp()
{
    System.setProperty("phantomjs.binary.path", "E:/PhantomJS/phantomjs-2.1.1-windows/bin/phantomjs.exe");
    driver = new PhantomJSDriver();
    System.out.println("=====PhantomJS Driver Initiated=====");
    driver.manage().window().maximize();
    driver.get("https://dev.investmentpunk.academy/");
    System.out.println("=====URL Accessed=====");
    wait = new WebDriverWait(driver, 10);
}

@Test
public void testGoogleSearch() throws InterruptedException
{
    WebElement Login_btn = driver.findElement(By.xpath("//ul/li[@class='ng-scope']/a[text()='EINLOGGEN']"));
    Login_btn.click();
    System.out.println("=====EINLOGGEN button Clicked=====");

    wait.until(ExpectedConditions.elementToBeClickable(By.xpath("//input[@placeholder='Username/Email']"))).sendKeys("user1");
    System.out.println("=====Username Sent=====");

    WebElement Password = driver.findElement(By.xpath("//input[@placeholder='Passwort']"));
    Password.sendKeys("qwerty");
    System.out.println("=====Password Sent=====");

    WebElement Login = driver.findElement(By.xpath("//button[@class='btn btn-blue']"));
    Login.click();
    System.out.println("=====Login button Clicked=====");
}

@AfterTest
public void tearDown()
{
    driver.quit();
}

}
</code>```

Fist error screenshot

Second error screenshot

答:
Here is the Answer to your Question:

A few words about the Solution:

The xpath you have constructed includes indexes. So they are brittle and vulnerable.

Just like class attribute we can use placeholder attribute too.

You have used @Before and @After Annotations from JUnit, instead I have used @BeforeTest and @AfterTest Annotations from TestNG and the below code block works fine:

```<code>public class Q44928902_GoogleSearchTest
{

    private WebDriver driver;
    private WebDriverWait wait;

    @BeforeTest
    public void SetUp()
    {
        System.setProperty("phantomjs.binary.path", "C:/Utility/phantomjs-2.1.1-windows/bin/phantomjs.exe");
        driver = new PhantomJSDriver();
        System.out.println("=====PhantomJS Driver Initiated=====");
        driver.manage().window().maximize();
        driver.get("https://dev.investmentpunk.academy");
        System.out.println("=====URL Accessed=====");
        wait = new WebDriverWait(driver, 10);
    }
    @Test
    public void testGoogleSearch() throws InterruptedException
    {
        WebElement Login_btn = driver.findElement(By.xpath("//ul/li[@class='ng-scope']/a[contains(@href,'/db/login/')][text()='EINLOGGEN']"));
        Login_btn.click();
        System.out.println("=====EINLOGGEN button Clicked=====");

        wait.until(ExpectedConditions.elementToBeClickable(By.xpath("//input[@placeholder='Username/Email']"))).sendKeys("user1");
        System.out.println("=====Username Sent=====");

        WebElement Password = driver.findElement(By.xpath("//input[@placeholder='Passwort']"));
        Password.sendKeys("qwerty");
        System.out.println("=====Password Sent=====");

        WebElement Login = driver.findElement(By.xpath("//button[@class='btn btn-blue']"));
        Login.click();
        System.out.println("=====Login button Clicked=====");
    }

    @AfterTest
    public void tearDown()
    {
        driver.quit();
    }
}
</code>```

Here is the output of the code block:

```<code>=====PhantomJS Driver Initiated=====
=====URL Accessed=====
=====EINLOGGEN button Clicked=====
=====Username Sent=====
=====Password Sent=====
=====Login button Clicked=====
[INFO  - 2017-07-06T09:58:41.996Z] ShutdownReqHand - _handle - About to shutdown
PASSED: testGoogleSearch

===============================================
    Default test
    Tests run: 1, Failures: 0, Skips: 0
===============================================
</code>```

Let me know if this Answers your Question.

Update [07/13/2017 - 19:00 IST]

I have re-run the same code and here is the result:

```<code>Jul 13, 2017 6:56:42 PM org.openqa.selenium.phantomjs.PhantomJSDriverService <init>
INFO: executable: C:\Utility\phantomjs-2.1.1-windows\bin\phantomjs.exe
Jul 13, 2017 6:56:42 PM org.openqa.selenium.phantomjs.PhantomJSDriverService <init>
INFO: port: 13867
Jul 13, 2017 6:56:42 PM org.openqa.selenium.phantomjs.PhantomJSDriverService <init>
INFO: arguments: [--webdriver=13867, --webdriver-logfile=C:\Users\AtechM_03\LearnAutmation\LearnAutomationTestNG\phantomjsdriver.log]
Jul 13, 2017 6:56:42 PM org.openqa.selenium.phantomjs.PhantomJSDriverService <init>
INFO: environment: {}
[INFO  - 2017-07-13T13:26:45.068Z] GhostDriver - Main - running on port 13867
[INFO  - 2017-07-13T13:26:46.224Z] Session [eb077d70-67ce-11e7-9bc6-6935b23fd504] - page.settings - {"XSSAuditingEnabled":false,"javascriptCanCloseWindows":true,"javascriptCanOpenWindows":true,"javascriptEnabled":true,"loadImages":true,"localToRemoteUrlAccessEnabled":false,"userAgent":"Mozilla/5.0 (Windows NT 6.2; WOW64) AppleWebKit/538.1 (KHTML, like Gecko) PhantomJS/2.1.1 Safari/538.1","webSecurityEnabled":true}
[INFO  - 2017-07-13T13:26:46.224Z] Session [eb077d70-67ce-11e7-9bc6-6935b23fd504] - page.customHeaders:  - {}
[INFO  - 2017-07-13T13:26:46.224Z] Session [eb077d70-67ce-11e7-9bc6-6935b23fd504] - Session.negotiatedCapabilities - {"browserName":"phantomjs","version":"2.1.1","driverName":"ghostdriver","driverVersion":"1.2.0","platform":"windows-8-32bit","javascriptEnabled":true,"takesScreenshot":true,"handlesAlerts":false,"databaseEnabled":false,"locationContextEnabled":false,"applicationCacheEnabled":false,"browserConnectionEnabled":false,"cssSelectorsEnabled":true,"webStorageEnabled":false,"rotatable":false,"acceptSslCerts":false,"nativeEvents":true,"proxy":{"proxyType":"direct"}}
[INFO  - 2017-07-13T13:26:46.225Z] SessionManagerReqHand - _postNewSessionCommand - New Session Created: eb077d70-67ce-11e7-9bc6-6935b23fd504
Jul 13, 2017 6:56:46 PM org.openqa.selenium.remote.ProtocolHandshake createSession
INFO: Detected dialect: OSS
=====PhantomJS Driver Initiated=====
=====URL Accessed=====
=====EINLOGGEN button Clicked=====
=====Username Sent=====
=====Password Sent=====
=====Login button Clicked=====
[INFO  - 2017-07-13T13:27:05.036Z] ShutdownReqHand - _handle - About to shutdown
PASSED: testGoogleSearch

===============================================
    Default test
    Tests run: 1, Failures: 0, Skips: 0
===============================================

===============================================
Default suite
Total tests run: 1, Failures: 0, Skips: 0
===============================================

[TestNG] Time taken by org.testng.reporters.EmailableReporter2@47caedad: 9 ms
[TestNG] Time taken by org.testng.reporters.XMLReporter@126253fd: 16 ms
[TestNG] Time taken by org.testng.reporters.SuiteHTMLReporter@1807f5a7: 246 ms
[TestNG] Time taken by org.testng.reporters.jq.Main@415b0b49: 151 ms
[TestNG] Time taken by [FailedReporter passed=0 failed=0 skipped=0]: 0 ms
[TestNG] Time taken by org.testng.reporters.JUnitReportReporter@642a7222: 65 ms
</code>```

Let me know exactly at which line you are facing the issue along with updating the full code & error stack trace in the Question area.

Body:
The submitted code was written only for the proof of concept of usage PhantomJS with Selenium.

I'm testing a Single Page Application.

Code works fine with GoogleChrome and FireFox, but can't find element with PhantomJS.

The problem is that driver finds "Login" button on Landing page (by xpath) BUT throws a TimeoutException:ExpectedCondition failed after trying to locate element by xpath when user was redirected on Login form.

I'm using:

Selenium 3.4.0

PhantomJS 2.1.1

My Code:

public class GoogleSearchTest
{

private WebDriver driver;
private WebDriverWait wait;

@Before
public void SetUp()
{
    System.setProperty("phantomjs.binary.path", "./src/test/resources/drivers/phantomjs.exe");
    driver = new PhantomJSDriver();
    driver.manage().window().maximize();
    driver.get("https://dev.investmentpunk.academy");
    wait = new WebDriverWait(driver, 10);
}
@Test
public void testGoogleSearch() throws InterruptedException
{
    WebElement Login_btn = driver.findElement(By.xpath("//ul/li[@class='ng-scope'][1]"));
    Login_btn.click();

    wait.until(ExpectedConditions.elementToBeClickable(By.xpath("//input[@class='c-input-db ng-pristine ng-untouched ng-empty ng-invalid ng-invalid-required ng-valid-minlength ng-valid-maxlength']"))).sendKeys("user1");

    WebElement Password = driver.findElement(By.xpath("//div[@class='form-row'][2]/input[@class='c-input-db ng-pristine ng-untouched ng-empty ng-invalid ng-invalid-required']"));
    Password.sendKeys("qwerty");

    WebElement Login = driver.findElement(By.xpath("//button[@class='btn btn-blue']"));
    Login.click();
}

@After
public void tearDown()
{
    driver.quit();
}

Please, help me to solve this issue.

======================Edited part======================

So, the case is that I'm running the code with TestNG (or with JUnit), using Your xpathes and it worked, until yesterday. So, driver is unable to locate a WebElement Login_btn = driver.findElement(By.xpath("//ul/li[@class='ng-scope']/a[text()='EINLOGGEN']")); I didn't provide any sugnificant changes in the code:

public class GoogleSearchTest
{
private WebDriver driver;
private WebDriverWait wait;

//second commit mess

@BeforeTest
public void SetUp()
{
    System.setProperty("phantomjs.binary.path", "E:/PhantomJS/phantomjs-2.1.1-windows/bin/phantomjs.exe");
    driver = new PhantomJSDriver();
    System.out.println("=====PhantomJS Driver Initiated=====");
    driver.manage().window().maximize();
    driver.get("https://dev.investmentpunk.academy/");
    System.out.println("=====URL Accessed=====");
    wait = new WebDriverWait(driver, 10);
}

@Test
public void testGoogleSearch() throws InterruptedException
{
    WebElement Login_btn = driver.findElement(By.xpath("//ul/li[@class='ng-scope']/a[text()='EINLOGGEN']"));
    Login_btn.click();
    System.out.println("=====EINLOGGEN button Clicked=====");

    wait.until(ExpectedConditions.elementToBeClickable(By.xpath("//input[@placeholder='Username/Email']"))).sendKeys("user1");
    System.out.println("=====Username Sent=====");

    WebElement Password = driver.findElement(By.xpath("//input[@placeholder='Passwort']"));
    Password.sendKeys("qwerty");
    System.out.println("=====Password Sent=====");

    WebElement Login = driver.findElement(By.xpath("//button[@class='btn btn-blue']"));
    Login.click();
    System.out.println("=====Login button Clicked=====");
}

@AfterTest
public void tearDown()
{
    driver.quit();
}

}

Fist error screenshot

Second error screenshot

Body:
Here is the Answer to your Question:

A few words about the Solution:

The xpath you have constructed includes indexes. So they are brittle and vulnerable.

Just like class attribute we can use placeholder attribute too.

You have used @Before and @After Annotations from JUnit, instead I have used @BeforeTest and @AfterTest Annotations from TestNG and the below code block works fine:

public class Q44928902_GoogleSearchTest
{

    private WebDriver driver;
    private WebDriverWait wait;

    @BeforeTest
    public void SetUp()
    {
        System.setProperty("phantomjs.binary.path", "C:/Utility/phantomjs-2.1.1-windows/bin/phantomjs.exe");
        driver = new PhantomJSDriver();
        System.out.println("=====PhantomJS Driver Initiated=====");
        driver.manage().window().maximize();
        driver.get("https://dev.investmentpunk.academy");
        System.out.println("=====URL Accessed=====");
        wait = new WebDriverWait(driver, 10);
    }
    @Test
    public void testGoogleSearch() throws InterruptedException
    {
        WebElement Login_btn = driver.findElement(By.xpath("//ul/li[@class='ng-scope']/a[contains(@href,'/db/login/')][text()='EINLOGGEN']"));
        Login_btn.click();
        System.out.println("=====EINLOGGEN button Clicked=====");

        wait.until(ExpectedConditions.elementToBeClickable(By.xpath("//input[@placeholder='Username/Email']"))).sendKeys("user1");
        System.out.println("=====Username Sent=====");

        WebElement Password = driver.findElement(By.xpath("//input[@placeholder='Passwort']"));
        Password.sendKeys("qwerty");
        System.out.println("=====Password Sent=====");

        WebElement Login = driver.findElement(By.xpath("//button[@class='btn btn-blue']"));
        Login.click();
        System.out.println("=====Login button Clicked=====");
    }

    @AfterTest
    public void tearDown()
    {
        driver.quit();
    }
}

Here is the output of the code block:

=====PhantomJS Driver Initiated=====
=====URL Accessed=====
=====EINLOGGEN button Clicked=====
=====Username Sent=====
=====Password Sent=====
=====Login button Clicked=====
[INFO  - 2017-07-06T09:58:41.996Z] ShutdownReqHand - _handle - About to shutdown
PASSED: testGoogleSearch

===============================================
    Default test
    Tests run: 1, Failures: 0, Skips: 0
===============================================

Let me know if this Answers your Question.

Update [07/13/2017 - 19:00 IST]

I have re-run the same code and here is the result:

Jul 13, 2017 6:56:42 PM org.openqa.selenium.phantomjs.PhantomJSDriverService <init>
INFO: executable: C:\Utility\phantomjs-2.1.1-windows\bin\phantomjs.exe
Jul 13, 2017 6:56:42 PM org.openqa.selenium.phantomjs.PhantomJSDriverService <init>
INFO: port: 13867
Jul 13, 2017 6:56:42 PM org.openqa.selenium.phantomjs.PhantomJSDriverService <init>
INFO: arguments: [--webdriver=13867, --webdriver-logfile=C:\Users\AtechM_03\LearnAutmation\LearnAutomationTestNG\phantomjsdriver.log]
Jul 13, 2017 6:56:42 PM org.openqa.selenium.phantomjs.PhantomJSDriverService <init>
INFO: environment: {}
[INFO  - 2017-07-13T13:26:45.068Z] GhostDriver - Main - running on port 13867
[INFO  - 2017-07-13T13:26:46.224Z] Session [eb077d70-67ce-11e7-9bc6-6935b23fd504] - page.settings - {"XSSAuditingEnabled":false,"javascriptCanCloseWindows":true,"javascriptCanOpenWindows":true,"javascriptEnabled":true,"loadImages":true,"localToRemoteUrlAccessEnabled":false,"userAgent":"Mozilla/5.0 (Windows NT 6.2; WOW64) AppleWebKit/538.1 (KHTML, like Gecko) PhantomJS/2.1.1 Safari/538.1","webSecurityEnabled":true}
[INFO  - 2017-07-13T13:26:46.224Z] Session [eb077d70-67ce-11e7-9bc6-6935b23fd504] - page.customHeaders:  - {}
[INFO  - 2017-07-13T13:26:46.224Z] Session [eb077d70-67ce-11e7-9bc6-6935b23fd504] - Session.negotiatedCapabilities - {"browserName":"phantomjs","version":"2.1.1","driverName":"ghostdriver","driverVersion":"1.2.0","platform":"windows-8-32bit","javascriptEnabled":true,"takesScreenshot":true,"handlesAlerts":false,"databaseEnabled":false,"locationContextEnabled":false,"applicationCacheEnabled":false,"browserConnectionEnabled":false,"cssSelectorsEnabled":true,"webStorageEnabled":false,"rotatable":false,"acceptSslCerts":false,"nativeEvents":true,"proxy":{"proxyType":"direct"}}
[INFO  - 2017-07-13T13:26:46.225Z] SessionManagerReqHand - _postNewSessionCommand - New Session Created: eb077d70-67ce-11e7-9bc6-6935b23fd504
Jul 13, 2017 6:56:46 PM org.openqa.selenium.remote.ProtocolHandshake createSession
INFO: Detected dialect: OSS
=====PhantomJS Driver Initiated=====
=====URL Accessed=====
=====EINLOGGEN button Clicked=====
=====Username Sent=====
=====Password Sent=====
=====Login button Clicked=====
[INFO  - 2017-07-13T13:27:05.036Z] ShutdownReqHand - _handle - About to shutdown
PASSED: testGoogleSearch

===============================================
    Default test
    Tests run: 1, Failures: 0, Skips: 0
===============================================

===============================================
Default suite
Total tests run: 1, Failures: 0, Skips: 0
===============================================

[TestNG] Time taken by org.testng.reporters.EmailableReporter2@47caedad: 9 ms
[TestNG] Time taken by org.testng.reporters.XMLReporter@126253fd: 16 ms
[TestNG] Time taken by org.testng.reporters.SuiteHTMLReporter@1807f5a7: 246 ms
[TestNG] Time taken by org.testng.reporters.jq.Main@415b0b49: 151 ms
[TestNG] Time taken by [FailedReporter passed=0 failed=0 skipped=0]: 0 ms
[TestNG] Time taken by org.testng.reporters.JUnitReportReporter@642a7222: 65 ms

Let me know exactly at which line you are facing the issue along with updating the full code & error stack trace in the Question area.


问:
Form validation with jquery - return false
Can some one tell my why the folowing code doesn't work. It alerts as it should. But it return true afterwards, even if a field is empty.</p>

```<code><form id="theform" method="post" action="mailme.php">
<input id="field1" name="a" value="field1" type="text" />
<input id="field2" name="b" value="field2" type="text" />
<input id="field3" name="c" value="field3" type="text" />
<input id="field4" name="d" value="field4" type="text" />

<input type="submit" />
</form>
<script>
$('#theform').submit(function(){
    $('#theform input[type=text]').each(function(n,element){
        if ($(element).val()=='') {
             alert('The ' + element.id+' must have a value');
             return false;
        }
    });
    return true;
});

</script>
</code>```

答:
You can also use jQuery's filter() function with a callback function, and then testing the resulting array for its size, returning true if it's zero.

```<code>$('#theform').submit(function(event) {
  var filtered = $('#theform input[type=text]').filter(function(index) {
    if ($(this).val() == '') {
      alert('The ' + this.id + ' must have a value');

      return true;
    }

    return false;
  });

  return filtered.length == 0;
});
</code>```

ContentLicense: CC BY-SA 2.5

Body:
Can some one tell my why the folowing code doesn't work. It alerts as it should. But it return true afterwards, even if a field is empty.

<form id="theform" method="post" action="mailme.php">
<input id="field1" name="a" value="field1" type="text" />
<input id="field2" name="b" value="field2" type="text" />
<input id="field3" name="c" value="field3" type="text" />
<input id="field4" name="d" value="field4" type="text" />

<input type="submit" />
</form>

Body:
You can also use jQuery's filter() function with a callback function, and then testing the resulting array for its size, returning true if it's zero.

$('#theform').submit(function(event) {
  var filtered = $('#theform input[type=text]').filter(function(index) {
    if ($(this).val() == '') {
      alert('The ' + this.id + ' must have a value');

      return true;
    }

    return false;
  });

  return filtered.length == 0;
});