I am trying to implement code where there are several elements. I can fill ListViewand display all of these elements, but I want to inflate the view onItemClick. Unfortunately, AdapterViewdoes not support addView().
So now I want to use addView()to dynamically add elements by moving ArrayList<>(). How to do it?
Basically, I want to display a custom keyboard layout next to the TextViewinside ListViewand update the valueTextView
This is what I'm trying to do now.
public class OrderSummary extends Activity {
LinearLayout linearLayout;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_order_summary);
linearLayout = new LinearLayout(this);
View view = View.inflate(this, R.layout.top_bar_layout, null);
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
linearLayout.addView(view, params);
view.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Toast.makeText(OrderSummary.this, "Clicked", Toast.LENGTH_SHORT).show();
}
});
}
}
source
share