logo
down
shadow

Get the TextView value of the gridview while clicking on an element


Get the TextView value of the gridview while clicking on an element

By : Augusto Afonso Borge
Date : October 21 2020, 08:10 AM
I wish this help you I am trying to get the value of TextView from gridView, when I click on an element of the list. The adapter consists of 2 textViews. This is the ListAdapter class. , This should work :
code :
gridViewCustomer.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> parent, View view,final int position, long id) {

                 Toast.makeText(ListActivity.this, "You have clicked on the element with id =" + id, Toast.LENGTH_SHORT).show();

                 Toast.makeText(ListActivity.this, "You have clicked on the element with name=" + customer.get(position).getName(), Toast.LENGTH_SHORT).show();

        }
    });


Share : facebook icon twitter icon
Jquery: Changing an element's ID by clicking on the element itself, then having it change back by clicking on the elemen

Jquery: Changing an element's ID by clicking on the element itself, then having it change back by clicking on the elemen


By : Chen An
Date : March 29 2020, 07:55 AM
will help you Use a class instead and toggle it on and off. IDs aren't really meant to be changed like that, classes are.
Also no need to swap out the entire stylesheet to hide some elements. Use a parent container and hide that.
How can we change the text of a textview on clicking of that textview in a custom list view if we are having lots of tex

How can we change the text of a textview on clicking of that textview in a custom list view if we are having lots of tex


By : Dan
Date : March 29 2020, 07:55 AM
seems to work fine I got solution of my above query.It works for me.. Here is the Sample of my code..
Adapter Class:
code :
public class CustomListAdapter  extends BaseAdapter implements OnClickListener
  {
 public Activity activity;
  private ArrayList<JSONObject>data;

public Context context;  
  public String furl;
  LayoutInflater inflater=null;

 public CustomListAdapter(Activity activity, ArrayList<JSONObject>data) {
  super();

  this.activity = activity;
  context=activity.getApplicationContext();
  this.data = data;  
   inflater = ( LayoutInflater)activity.
        getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    }

 @Override
    public int getCount()
    {
     return data.size();
      }
  @Override
 public long getItemId(int position)
  {  
  return position;
  }


@Override
public Object getItem(int position) 
{
    return data.get(position);
}



       public static class ViewHolder
       {

        public TextView txtShort;
          public TextView txtLong;       
         public TextView txtMore;        
      }

   @Override
  public View getView(int position, View convertView, ViewGroup Parent) 
    {   
 View view=convertView;
 if (view==null) {
     convertView= inflater.inflate(R.layout.layout_row, null);
}

  final TextView txtShort=(TextView) convertView.findViewById(R.id.text_main);
  final TextView txtLong=(TextView) convertView.findViewById(R.id.text_detail);
  final TextView txtMore=(TextView) convertView.findViewById(R.id.text_more);


   if(data.size()<=0)
   {

   Toast.makeText(activity, "No data", Toast.LENGTH_LONG).show();
   }
  else
 {
   try{
      final JSONObject jsonObject=data.get(position);
      txtShort.setText(jsonObject.getString("name"));
       if (jsonObject.getBoolean("isExpand")==true)
       {
           txtLong.setVisibility(View.VISIBLE); 
           txtShort.setVisibility(View.GONE);   
      }else
      {

          txtLong.setVisibility(View.GONE); 
         txtShort.setVisibility(View.VISIBLE);  
      }

       txtMore.setOnClickListener(new View.OnClickListener() 
       {

        @Override
        public void onClick(View v) 
        {

            try {

                if (jsonObject.getBoolean("isExpand")==true) 
                {
                    txtLong.setVisibility(View.GONE);   
                    txtShort.setVisibility(View.VISIBLE);
                    jsonObject.put("isExpand",false);
                }else
                {                           
                    txtLong.setVisibility(View.VISIBLE);    
                      txtShort.setVisibility(View.GONE);
                      jsonObject.put("isExpand",true);
                }
            } catch (JSONException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        }
    });
   }catch(Exception ex)
   {

   }
  }
public class MainActivity extends Activity {

ListView listView=null;
ArrayList<JSONObject> arrayListjsonObj=new ArrayList<JSONObject>();
CustomListAdapter adapter=null;
@Override
protected void onCreate(Bundle savedInstanceState) 
{
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    listView=(ListView)findViewById(R.id.listView1);
    insertjsonObject();
    adapter=new CustomListAdapter(MainActivity.this, arrayListjsonObj);
    listView.setAdapter(adapter);

}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.main, menu);

    return true;
}



public void insertjsonObject()
{
    arrayListjsonObj.clear();
    for (int i = 0; i < 50; i++) {
    try {
        JSONObject jsonObject=new JSONObject();
        jsonObject.put("name", "name "+i);
        jsonObject.put("address", "address "+i);
        jsonObject.put("isExpand", false);
        arrayListjsonObj.add(jsonObject);
    } catch (Exception e) 
    {

    }

}   
Return the corresponding SelectedValue of DropDownList in GridView after clicking the Button in GridView

Return the corresponding SelectedValue of DropDownList in GridView after clicking the Button in GridView


By : Aslam Memon
Date : March 29 2020, 07:55 AM
help you fix your problem Following code might help. 1st code block is for GridView , i am assuming you have used like this. Idea is to have an TemplateField and have gridview with rowcommand event set. TemplateField will have LinkButton ,having command name = CartAdd, and when RowCommand is fired, you get that event in 2nd code block and from there get corresponding selected value for DropDownList.
code :
<asp:GridView ID="gvw" 
AutoGenerateColumns="False" 
            runat="server"  
            onrowcommand="gvw_RowCommand">

.... .
    <asp:TemplateField HeaderText="View More">
    <ItemTemplate>
        <asp:LinkButton ID="btnCartAdd" CommandArgument='<%# Container.DataItemIndex %>'
            CommandName="CartAdd" runat="server" Text="Add to cart" />
    </ItemTemplate>
   </asp:TemplateField>
Protected Sub gvw_RowCommand(ByVal sender As Object, ByVal e As GridViewCommandEventArgs)
    If e.CommandName = "CartAdd" Then
        Dim index As Integer = Convert.ToInt32(e.CommandArgument.ToString())
        Dim ddl As DropDownList = CType(gvw.Rows(index).FindControl("DDL_ID"), DropDownList) 'replce DDL_ID with required id used for dropdownlist
        Dim val As String = ddl.SelectedValue
    End If
End Sub
JS function when clicking parent element but return false when clicking child element

JS function when clicking parent element but return false when clicking child element


By : Jie Sun
Date : March 29 2020, 07:55 AM
hop of those help? I think you mignt want to use event.stopPropagation():
code :
function new_image_click(e) {
    e.stopPropagation();
}

new_image.setAttribute("onclick", "new_image_click(event)");
How does one expand/collapse a nested GridView embedded within div element while clicking an ImageButton?

How does one expand/collapse a nested GridView embedded within div element while clicking an ImageButton?


By : Pók
Date : March 29 2020, 07:55 AM
fixed the issue. Will look into that further For the following code , Add the following javascript function:
Related Posts Related Posts :
  • How to employ keyed-hash message authentication code (HMAC) with Android Keystore
  • Prevent inviting existing users or previously invited
  • How to overwrite windowSoftInputMode using edit-config tag in cordova
  • Difference between Loader and AsyncTask
  • In Firebase Android, retrieve the value of a child node and save it in a boolean variable
  • when i scroll the custom list in my android app then the favorite icon which is part of the custom adapter changes on it
  • adding room dependency gives manifest merge error
  • Visibility of RelativeLayout change on scrolling Gridview
  • Strange LiveData behavior vs ObservableField
  • Which layout is used for clash of clans home screen? We can scroll it horizontal as well as vertical. Please illuminate
  • RxJava: Know when observable is finished and return Boolean Observable to the caller
  • how to use savedInstanceState to save camera information when the orientation change occure
  • Style React-Native via Styles.xml
  • Keyboard won't show after calling InputMethodManager.showSoftInput
  • Compiling ffmpeg for Android on OSX
  • Button does not get clicked on the first attempt
  • AR Core performance, learning curve and comparison with other frameworks
  • Codename one : Attaching images to email message fails
  • Error: Unsupported type 'viewItem' in Android build
  • setLayoutParams on ConstraintLayout does not change size
  • How to profile the fetch time of the android gradle libraries
  • Kotlin setOnclickListener
  • Naming convention for methods returning RxJava's Completable
  • Conv3D not working
  • FFmpeg audio video merge command
  • Do you have to use gradle-experimental for JNI?
  • How to get key hashes for facebook for facebook app?
  • ZXing not calling onActivityResult, When scanning QR Code
  • Integration of Android Native module with existing Xamarin Native Project
  • Restore RecyclerView state after rotating
  • ViewModelProviders java.lang.RuntimeException trying to instantiate class which inherit AndroidViewModel
  • SKD19 vs SDK24 - Usage of API documented as @since 1.8+
  • filter option in list view fragment activity
  • Picture from camera not showing up in second activity
  • How to change imageview according to screen size
  • How to copy Android Studio project to remote Git (NOT GitHub) server
  • How to get React-Native to announce specific accessibility message via AccessibiliyManager?
  • Change colors of com.tech.freak.wizardpager.ui.StepPagerStrip
  • Android fullscreen activity shows ActionBar
  • Turn on the screen when timer calls onFinish()
  • Would like a bit of clarification with SQLite database's onUpgrade method
  • Use ObjectBox with Libgdx
  • How to make combine Gregorian and Hijri calendar in Android?
  • Try to read text file from sdcard in other language
  • "App not installed" message when installed apk
  • How to execute a designated test suite class in Firebase Test Lab
  • play music with background service
  • background not visible on LG G3
  • should every View have an id?
  • Realm object server sync on low connection.
  • Correct way to add more views to adapter
  • Getting error in android support library
  • Instant app zip uploading error
  • "No emulator installed" error in Android Studio even though Intel HAXM is up and running
  • AsyncTask without leaks
  • SQLiteException : No such table found whereas a table was created
  • Using @Component.Builder with constructor params
  • No injector was found for fragment dagger 2.11
  • Android Volley Https SSL self signed and Google Maps API
  • Why does the onClickListener not work anymore in this example?
  • shadow
    Privacy Policy - Terms - Contact Us © voile276.org