Android looks for layout instead of layout-large when Activity is started for the second time
Date : March 29 2020, 07:55 AM
Hope this helps The origin of the error was in an external library I used: They were constructing an object subclassed from android.content.res.Resources to fake an in-memory resource. The Resources object's construction required an AssetManager as one of the parameters, which has been obtained using the Activity's getAssets() method. It seems that this was corrupting the resources.
|
Android loading data to a table layout in run-time
Tag : android , By : Gianluca Riccardi
Date : March 29 2020, 07:55 AM
it helps some times In my Android app I have to display data taken from a db in a table layout. I get the data and when I adding TableRaws to the Table it gives an Null-pointer. I properly instantiate the elements in the table and I cant figure out the error. My code snippet is as below.... // try this way i gave simple demo but you have use your data rather my static data..
1. **table.xml**
<?xml version="1.0" encoding="utf-8"?>
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/dpl_tbl_lst"
android:layout_width="match_parent"
android:layout_height="match_parent">
</TableLayout>
2.**table_row.xml**
<?xml version="1.0" encoding="utf-8"?>
<TableRow xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/dpl_tbl_hdr"
android:layout_width="match_parent"
android:orientation="horizontal"
android:layout_height="wrap_content">
<TextView
android:id="@+id/dpl_txt_seq"
android:layout_width="0dp"
android:layout_weight="1"
android:gravity="center"
android:layout_height="wrap_content"
android:text="asd"/>
<TextView
android:id="@+id/dpl_txt_cus_nm"
android:layout_width="0dp"
android:layout_weight="1"
android:gravity="center"
android:layout_height="wrap_content"
android:text="asd"/>
<TextView
android:id="@+id/dpl_txt_cty"
android:layout_width="0dp"
android:layout_weight="1"
android:gravity="center"
android:layout_height="wrap_content"
android:text="asd"/>
<TextView
android:id="@+id/dpl_txt_sts"
android:layout_width="0dp"
android:layout_weight="1"
android:gravity="center"
android:layout_height="wrap_content"
android:text="asd"/>
</TableRow>
3. **MyActivity.java**
public class MyActivity extends Activity {
TableLayout dpl_tbl_lst;
@Override
protected void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.table);
dpl_tbl_lst = (TableLayout) findViewById(R.id.dpl_tbl_lst);
for (int i=0;i<5;i++){
View row = LayoutInflater.from(this).inflate(R.layout.table_row,null,false);
TextView dpl_txt_seq = (TextView) row.findViewById(R.id.dpl_txt_seq);
TextView dpl_txt_cus_nm = (TextView) row.findViewById(R.id.dpl_txt_cus_nm);
TextView dpl_txt_cty = (TextView) row.findViewById(R.id.dpl_txt_cty);
TextView dpl_txt_sts = (TextView) row.findViewById(R.id.dpl_txt_sts);
dpl_txt_seq.setText("Seq"+String.valueOf(i+1));
dpl_txt_cus_nm.setText("Nm"+String.valueOf(i+1));
dpl_txt_cty.setText("City"+String.valueOf(i+1));
dpl_txt_sts.setText("Sts"+String.valueOf(i+1));
dpl_txt_seq.setTag("Seq"+String.valueOf(i+1));
dpl_txt_seq.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
String data = view.getTag().toString();
Toast.makeText(MyActivity.this,data,Toast.LENGTH_SHORT).show();
}
});
dpl_txt_cus_nm.setTag("Nm"+String.valueOf(i+1));
dpl_txt_cus_nm.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
String data = view.getTag().toString();
Toast.makeText(MyActivity.this,data,Toast.LENGTH_SHORT).show();
}
});
dpl_txt_cty.setTag("City"+String.valueOf(i+1));
dpl_txt_cty.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
String data = view.getTag().toString();
Toast.makeText(MyActivity.this,data,Toast.LENGTH_SHORT).show();
}
});
dpl_txt_sts.setTag("Sts"+String.valueOf(i+1));
dpl_txt_sts.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
String data = view.getTag().toString();
Toast.makeText(MyActivity.this,data,Toast.LENGTH_SHORT).show();
}
});
dpl_tbl_lst.addView(row);
}
}
}
|
How to construct a keyboard hints layout in android
Date : March 29 2020, 07:55 AM
This might help you , use popupWindow. show popupView above your key view. private void showPopUp(View v) {
LinearLayout layout = new LinearLayout(this);
layout.setBackgroundColor(Color.GRAY);
TextView tv = new TextView(this);
tv.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
tv.setText("I'm a pop -----------------------------!");
tv.setTextColor(Color.WHITE);
layout.addView(tv);
popupWindow = new PopupWindow(layout,120,120);
popupWindow.setFocusable(true);
popupWindow.setOutsideTouchable(true);
popupWindow.setBackgroundDrawable(new BitmapDrawable());
int[] location = new int[2];
v.getLocationOnScreen(location);
popupWindow.showAtLocation(v, Gravity.NO_GRAVITY, location[0], location[1]-popupWindow.getHeight());
}
|
android - Load progress bar layout before loading main layout
Date : March 29 2020, 07:55 AM
I wish this help you I'm not sure I understood your question, but I'd suggest you to write something like this in your activity: private Handler mHandler;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.your_layout);
mHandler = new Handler(Looper.getMainLooper());
mHandler.postDelayed(new Runnable() {
public void run() {
// hide your progress bar
findViewById(R.id.progressBar).setVisibility(View.GONE);
// or finish this activity and start a new one
startActivity(new Intent(MyActivity.this, MySecondActivity.class));
}
}, 5000);
}
@Override
public void onDestroy() {
super.onDestroy();
mHandler.removeCallbacks(null);
}
|
How to know how much time take for loading layout in android?
Tag : android , By : Lauren Kirschner
Date : March 29 2020, 07:55 AM
will be helpful for those in need I want to check which layout is loading fast with the same design like Relative Layout, Linear Layout or Constraint Layout but I can't get any tool or any idea about that so please help me out for my query. , I think this trick may help you. long time1 = System.currentTimeMillis();
setContentView(R.layout.activity_main);
long time2 = System.currentTimeMillis();
Log.i(TAG, "onCreate: " + (time2 - time1));
|