`# Dears, this class works well to receive PDF files from another application on below Android 6, but it gives an error for Android uper 6
` #RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
public int ExtractImage(Intent intent) {
try {
String filepath = null;
if (intent != null) {
String action = intent.getAction();
String type = intent.getType();
if (Intent.ACTION_VIEW.equals(action) && type.endsWith("pdf")) {
Uri file_uri = intent.getData();
if (file_uri != null) {
filepath = file_uri.getPath();
}
} else if (Intent.ACTION_SEND.equals(action) && type.endsWith("pdf")) {
Uri uri = intent.getParcelableExtra(Intent.EXTRA_STREAM);
if (uri != null) {
filepath = uri.getPath();
}
}
}
File file = new File(filepath);
PdfRenderer renderer = null;
Bitmap bm;
try {
renderer = new PdfRenderer(ParcelFileDescriptor.open(file,
ParcelFileDescriptor.MODE_READ_ONLY));
} catch (Exception e) {
}
assert renderer != null;
final int pageCount = renderer.getPageCount();
totalPage = pageCount;
for (int i = 0; i < pageCount; i++) {
PdfRenderer.Page page = renderer.openPage(i);
// Create a bitmap and canvas to draw the page into
int width = 570;
int zarib = 570 / (page.getWidth() + 1);
int height = (page.getHeight() * 2) + 1;
heightArray.add(i, height);
// Create a bitmap and canvas to draw the page into
bm = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
// Create canvas to draw into the bitmap
Canvas c = new Canvas(bm);
// Fill the bitmap with a white background
Paint whiteBgnd = new Paint();
whiteBgnd.setColor(Color.WHITE);
whiteBgnd.setStyle(Paint.Style.FILL);
c.drawRect(0, 0, width, height, whiteBgnd);
// paint the page into the canvas
page.render(bm, null, null, PdfRenderer.Page.RENDER_MODE_FOR_PRINT);
// Save the bitmap
OutputStream outStream = null;
try {
outStream = new
FileOutputStream(Environment.getExternalStorageDirectory().getAbsolutePath()
+ "/printDo2ta" + i + ".png");
} catch (Exception e) {
e.printStackTrace();
}
bm.compress(Bitmap.CompressFormat.PNG, 80, outStream);
try {
outStream.close();
} catch (Exception e) {
e.printStackTrace();
}
page.close();
}
} catch (Exception e) {
runOnUiThread(() -> Toast.makeText(getBaseContext(),
"خطا در پردازش فایل: " + e.getMessage(),
Toast.LENGTH_SHORT).show());
}
return totalPage;
}
I inserted this code in AndroidManifest.xml
`<provider
android:name="androidx.core.content.FileProvider"
android:authorities="ir.myproject.test.fileprovider"
android:exported="false"
android:grantUriPermissions="true">
<meta-data
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="#xml/provider_paths" />
</provider>`
`
And I made the class provider_paths.xml
`<?xml version="1.0" encoding="utf-8"?>
<paths>
<external-path name="external_files" path="."/>
</paths>`
I don't know what else I need to change to make it work on Android 8
please help me`
i have a recyclerview the has an edittext in each row. the user can change the value of the edittext as he wishes but it should not be left empty for the values will be saved in a database. for this i'm trying to check if the edittext is empty. if any row has an empty edittext, the user is given a message when he wants to save that there is an empty value. this is the code that i wrote:
public class recyclerview_viewholder : RecyclerView.ViewHolder
{
public TextView rownbr, itemname;
public EditText qty;
public TextView unit;
public LinearLayout linearLayout;
public recyclerview_viewholder(View itemView, Action<int> listener)
: base(itemView)
{
rownbr = itemView.FindViewById<TextView>(Resource.Id.rownbr);
itemname = itemView.FindViewById<TextView>(Resource.Id.laborname);
unit = itemView.FindViewById<TextView>(Resource.Id.days);
qty = itemView.FindViewById<EditText>(Resource.Id.overtime);
linearLayout = itemView.FindViewById<LinearLayout>(Resource.Id.linearLayout);
itemView.Click += (sender, e) => listener(base.LayoutPosition);
}
}
public class recyclerviewAdapter : RecyclerView.Adapter
{
// Event handler for item clicks:
public event EventHandler<int> ItemClick;
DataTable summary_Requests = new DataTable();
//Context context;
public readonly new_request_items context;
int selected_pos = -1;
private SwipeToDeleteCallback swipeToDeleteCallback;
List<list_item> item_details = new List<list_item>();
public recyclerviewAdapter(new_request_items context, DataTable sum_req, List<list_item> item_details)
{
this.context = context;
summary_Requests = sum_req;
this.item_details = item_details;
}
public recyclerviewAdapter(DataTable sum_req, SwipeToDeleteCallback swipeToDeleteCallback)
{
this.swipeToDeleteCallback = swipeToDeleteCallback;
summary_Requests = sum_req;
}
public override RecyclerView.ViewHolder
OnCreateViewHolder(ViewGroup parent, int viewType)
{
View itemView = LayoutInflater.From(parent.Context).
Inflate(Resource.Layout.recycler_view_request_new_data, parent, false);
recyclerview_viewholder vh = new recyclerview_viewholder(itemView, OnClick);
vh.qty.TextChanged += (sender, e) =>
{
if (vh.qty.Text != "")
try
{
int position = vh.LayoutPosition;
summary_Requests.Rows[position]["itemQty"] = Convert.ToDecimal(vh.qty.Text);
user.zero_val = "Not_exist";
}
catch (System.FormatException exp)
{
var icon = AppCompatResources.GetDrawable(context.Context, Resource.Drawable.error_ic);
icon.SetBounds(0, 0, 50, 50);
vh.qty.SetError("qty can be decimal", icon);
user.zero_val = "exits";
}
else if (vh.qty.Text == "")
{
var icon = AppCompatResources.GetDrawable(context.Context, Resource.Drawable.error_ic);
icon.SetBounds(0, 0, 50, 50);
vh.qty.SetError("value can not be empty", icon);
user.zero_val = "exits";
}
};
vh.ItemView.LongClick += (sender, e) =>
{
int position = vh.AdapterPosition;
string itemcode = summary_Requests.Rows[position]["itemcode"].ToString();
list_item result = item_details.Find(list_item => list_item.item_code == itemcode);
Bundle bundle = new Bundle();
bundle.PutString("result", JsonConvert.SerializeObject(result));
items_info iteminf = new items_info();
iteminf.Arguments = bundle;
iteminf.Cancelable = true;
var SupportFragmentManager = this.context.FragmentManager;
iteminf.Show(SupportFragmentManager, "dialog");
selected_pos = position;
NotifyDataSetChanged();
//fill global variables that need to be passed to detail fragment
};
return vh;
}
public override void
OnBindViewHolder(RecyclerView.ViewHolder holder, int position)
{
recyclerview_viewholder vh = holder as recyclerview_viewholder;
vh.rownbr.Text = summary_Requests.Rows[position]["rowNumber"].ToString();
vh.itemname.Text = summary_Requests.Rows[position]["name"].ToString();
vh.unit.Text = summary_Requests.Rows[position]["itemsunitcode"].ToString();
vh.qty.Text= summary_Requests.Rows[position]["itemQty"].ToString();
if (selected_pos == position)
vh.ItemView.SetBackgroundColor(Color.ParseColor("#4fa5d5"));
else
vh.ItemView.SetBackgroundColor(Color.LightGray);
}
public void RemoveItem(int position)
{
if (laborers_dt_total.Rows.Count != 0)
{
if (position < laborers_dt_total.Rows.Count && position > -1)
{
laborers_dt_total.Rows.RemoveAt(position);
}
else
{
Toast.MakeText(context.Context, "select an item to delete", ToastLength.Long).Show();
}
}
else if (laborers_dt_total.Rows.Count == 0)
{
Toast.MakeText(context.Context, "no items to delete", ToastLength.Long).Show();
}
for (int i = 0; i < laborers_dt_total.Rows.Count; i++)
{
laborers_dt_total.Rows[i]["rowNumber"] = (i + 1).ToString();
NotifyDataSetChanged();
}
}
public DataTable get_dt_final()
{
DataTable final_dt = summary_Requests.Copy();
return final_dt;
}
public override int ItemCount
{
get { return summary_Requests.Rows.Count; }
}
// Raise an event when the item-click takes place:
void OnClick(int position)
{
if (ItemClick != null)
ItemClick(this, position);
// user.req_pos = position;
}
}
now it works well when there are only few rows in the recyclerview, but when there are many in which i have to scroll through it, if i keep an edittext empty in a row reached by scrolling, the user.zero_val doesn't take the value of exits to tell me that an edittext is empty. what should i do in this case? where do i check for empty edittext? thanks in advance.
this is a simple code i wrote with hopes it would illustrate my problem:
this is the axml of the recyclerview:
<?xml version="1.0" encoding="utf-8"?>
<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">
<android.support.v7.widget.RecyclerView
android:minWidth="25px"
android:minHeight="25px"
android:layout_width="match_parent"
android:layout_height="255sp"
android:id="#+id/recyclerView1" />
<Button
android:text="Button"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/button1" />
</LinearLayout>
this is the layout of each row of the recyclerview:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#color/light_grey"
android:padding="1dp"
android:layout_marginTop="0.5dp"
android:weightSum="8"
android:gravity="center"
android:id="#+id/linearLayout"
>
<TextView
android:text=""
android:layout_width="0dp"
android:layout_height="50dp"
android:layout_weight="2"
android:id="#+id/rownbr"
android:background="#drawable/back"
android:paddingLeft="1dp"
android:paddingRight="1dp"
android:textSize="12dp"
android:gravity="center"
android:textColor="#000000"
/>
<TextView
android:text=""
android:layout_width="0dp"
android:layout_height="50dp"
android:layout_weight="4"
android:id="#+id/laborname"
android:paddingLeft="1dp"
android:paddingRight="1dp"
android:textSize="12dp"
android:gravity="center"
android:textColor="#000000"
android:background="#drawable/back"
android:layout_marginLeft="2dp"/>
<TextView
android:text=""
android:layout_width="0dp"
android:layout_height="50dp"
android:layout_weight="1"
android:id="#+id/days"
android:paddingLeft="1dp"
android:paddingRight="1dp"
android:textSize="12dp"
android:textColor="#000000"
android:layout_marginLeft="2dp"
android:gravity="center"
android:background="#drawable/back"/>
<EditText
android:text=""
android:layout_width="0dp"
android:layout_height="50dp"
android:layout_weight="1"
android:id="#+id/overtime"
android:paddingLeft="1dp"
android:paddingRight="1dp"
android:textSize="12dp"
android:textColor="#000000"
android:layout_marginLeft="2dp"
android:gravity="center"
android:background="#drawable/back"/>
</LinearLayout>
this is the back.xml drawable:
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle" >
<solid android:color="#android:color/white" />
<stroke android:width="1dip" android:color="#4fa5d5"/>
</shape>
this is the activity where the recyclerview is populated and managed:
public class MainActivity : AppCompatActivity
{
RecyclerView mRecyclerView;
DataTable dt = new DataTable();
RecyclerView.LayoutManager mLayoutManager;
recyclerviewAdapter RecyclerviewAdapter;
protected override void OnCreate(Bundle savedInstanceState)
{
base.OnCreate(savedInstanceState);
// Set our view from the "main" layout resource
SetContentView(Resource.Layout.activity_main);
dt.Columns.Add("rowNumber");
dt.Columns.Add("name");
dt.Columns.Add("itemsunitcode");
dt.Columns.Add("itemQty");
dt.Rows.Add("1", "rana hd", "pcs", "1");
dt.Rows.Add("2", "rana hd1", "pcs", "1");
dt.Rows.Add("3", "rana hd2", "pcs", "1");
dt.Rows.Add("4", "rana hd3", "pcs", "1");
dt.Rows.Add("5", "rana hd4", "pcs", "1");
dt.Rows.Add("6", "rana hd5", "pcs", "1");
dt.Rows.Add("7", "rana hd6", "pcs", "1");
dt.Rows.Add("8", "rana hd7", "pcs", "1");
dt.Rows.Add("9", "rana hd8", "pcs", "1");
dt.Rows.Add("10", "rana hd9", "pcs", "1");
mRecyclerView = FindViewById<RecyclerView>(Resource.Id.recyclerView1);
Button btn= FindViewById<Button>(Resource.Id.button1);
mLayoutManager = new LinearLayoutManager(this);
mRecyclerView.HasFixedSize = true;
mRecyclerView.SetLayoutManager(mLayoutManager);
RecyclerviewAdapter = new recyclerviewAdapter(this, dt);
mRecyclerView.SetAdapter(RecyclerviewAdapter);
btn.Click += delegate
{
if (user.zero_val == "exits")
Toast.MakeText(this, "exists", ToastLength.Long).Show();
if (user.zero_val == "Not_exist")
Toast.MakeText(this, "Not_exist", ToastLength.Long).Show();
};
}
public class recyclerview_viewholder : RecyclerView.ViewHolder
{
public TextView rownbr, itemname;
public EditText qty;
public TextView unit;
public LinearLayout linearLayout;
public recyclerview_viewholder(View itemView, Action<int> listener)
: base(itemView)
{
rownbr = itemView.FindViewById<TextView>(Resource.Id.rownbr);
itemname = itemView.FindViewById<TextView>(Resource.Id.laborname);
unit = itemView.FindViewById<TextView>(Resource.Id.days);
qty = itemView.FindViewById<EditText>(Resource.Id.overtime);
linearLayout = itemView.FindViewById<LinearLayout>(Resource.Id.linearLayout);
itemView.Click += (sender, e) => listener(base.LayoutPosition);
}
}
public class recyclerviewAdapter : RecyclerView.Adapter
{
// Event handler for item clicks:
public event EventHandler<int> ItemClick;
DataTable summary_Requests = new DataTable();
//Context context;
public readonly MainActivity context;
int selected_pos = -1;
public recyclerviewAdapter(MainActivity context, DataTable sum_req)
{
this.context = context;
summary_Requests = sum_req;
}
public override RecyclerView.ViewHolder
OnCreateViewHolder(ViewGroup parent, int viewType)
{
View itemView = LayoutInflater.From(parent.Context).
Inflate(Resource.Layout.recyclerview_data, parent, false);
recyclerview_viewholder vh = new recyclerview_viewholder(itemView, OnClick);
vh.qty.TextChanged += (sender, e) =>
{
if (vh.qty.Text != "")
try
{
int position = vh.LayoutPosition;
summary_Requests.Rows[position]["itemQty"] = Convert.ToDecimal(vh.qty.Text);
user.zero_val = "Not_exist";
}
catch (System.FormatException exp)
{
var icon = AppCompatResources.GetDrawable(context, Resource.Drawable.error_ic);
icon.SetBounds(0, 0, 50, 50);
vh.qty.SetError("qty can be decimal", icon);
user.zero_val = "exits";
}
else if (vh.qty.Text == "")
{
var icon = AppCompatResources.GetDrawable(context, Resource.Drawable.error_ic);
icon.SetBounds(0, 0, 50, 50);
vh.qty.SetError("value can not be empty", icon);
user.zero_val = "exits";
}
};
vh.ItemView.LongClick += (sender, e) =>
{
int position = vh.AdapterPosition;
selected_pos = position;
NotifyDataSetChanged();
};
return vh;
}
public override void
OnBindViewHolder(RecyclerView.ViewHolder holder, int position)
{
recyclerview_viewholder vh = holder as recyclerview_viewholder;
vh.rownbr.Text = summary_Requests.Rows[position]["rowNumber"].ToString();
vh.itemname.Text = summary_Requests.Rows[position]["name"].ToString();
vh.unit.Text = summary_Requests.Rows[position]["itemsunitcode"].ToString();
vh.qty.Text = summary_Requests.Rows[position]["itemQty"].ToString();
if (selected_pos == position)
vh.ItemView.SetBackgroundColor(Color.ParseColor("#4fa5d5"));
else
vh.ItemView.SetBackgroundColor(Color.LightGray);
}
public DataTable get_dt_final()
{
DataTable final_dt = summary_Requests.Copy();
return final_dt;
}
public override int ItemCount
{
get { return summary_Requests.Rows.Count; }
}
// Raise an event when the item-click takes place:
void OnClick(int position)
{
if (ItemClick != null)
ItemClick(this, position);
// user.req_pos = position;
}
}
}
}
this is the user class:
public static class user
{
public static string zero_val = "";
}
If I undstand your meanings correctly, I don't think it's correct to use variable zero_val in class user to indicate whether or not null values exist.For example ,if you have enter a empty value for the first EditText, then the value of zero_val will been changed to Not_exist, then if we enter another empty value for the second EditText, then the value of zero_val will also been changed to Not_exist,after that, if we change the second EditText to a correct value, then the value of zero_val will been changed to exits.But now, actually the first EditText still be empty.
I think you can verify the values the table DataTable when clicking button.
You can refer to the following code:
btn.Click += delegate
{
bool hasEmpty = false ;
foreach (DataRow row in dt.Rows)
{
string itemQty = row["itemQty"].ToString();
string rowNumber = row["rowNumber"].ToString();
System.Diagnostics.Debug.WriteLine("rowNumber =" + rowNumber + "< --- > itemQty = " + itemQty);
if (string.IsNullOrEmpty(itemQty)) {
hasEmpty = true;
}
}
//if (user.zero_val.Equals("exits"))
// Toast.MakeText(this, "exists", ToastLength.Long).Show();
//if (user.zero_val.Equals("Not_exist"))
// Toast.MakeText(this, "Not_exist", ToastLength.Long).Show();
if (!hasEmpty)
Toast.MakeText(this, "exists", ToastLength.Long).Show();
else
Toast.MakeText(this, "Not_exist", ToastLength.Long).Show();
};
In addition, modify the TextChanged function in RecyclerviewAdapter:
vh.qty.TextChanged += (sender, e) =>
{
if (!vh.qty.Text.Equals(""))
try
{
int position = vh.LayoutPosition;
summary_Requests.Rows[position]["itemQty"] = Convert.ToDecimal(vh.qty.Text);
}
catch (System.FormatException exp)
{
var icon = AppCompatResources.GetDrawable(context, Resource.Drawable.error);
icon.SetBounds(0, 0, 50, 50);
vh.qty.SetError("qty can be decimal", icon);
//store a empty value for this textview
int position = vh.LayoutPosition;
summary_Requests.Rows[position]["itemQty"] = "";
}
else if (vh.qty.Text.Equals(""))
{
var icon = AppCompatResources.GetDrawable(context, Resource.Drawable.error);
int position = vh.LayoutPosition;
//store a empty value for this textview
summary_Requests.Rows[position]["itemQty"] = "";
icon.SetBounds(0, 0, 50, 50);
vh.qty.SetError("value can not be empty", icon);
}
};
I am experiencing an issue regarding recyclerview item click, as the viewholder(item) has a textview inside it and I am implementing click on that textview.
What I am facing that , when I have put breakpoint inside that holder.textview.setOnclicklistener code block, I have found out that my control is going automatically inside that code block without clicking that item physically/manually.
I haven't called textview.performClick anywhere in that code.
Can anyone explain that??
code block of onBindViewhOlder
#Override
public void onBindViewHolder(ViewHolder holder, final int position) {
holder.txt_passeger.setText(passengerArrayList.get(position).getPaxFullName());
holder.txt_passeger.setTag("Unselected");
holder.img_tick_mark.setVisibility(View.GONE);
holder.txt_passeger.setTextColor(Color.BLACK);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
holder.lyt_background.setBackground(context.getResources().getDrawable(R.color.color_white));
}
holder.txt_seat_number.setVisibility(View.GONE);
//set seat number from map
//HashMap<String, HashMap<Integer, PassengerArray>> mapRoutePaxSeat (static data)
HashMap<Integer, PassengerArray> mapPaxSeat = FlightSeatViewFragment.mapIfsLegPaxSeat.get(ifsIndex + "_" + legIndex);
if (mapPaxSeat != null) {
//here the mapIfsLegPaxSeat is filled with ifs+legIndex that why mapPaxSeat is not null
Set<Integer> intSetPaxKey = mapPaxSeat.keySet();
Iterator<Integer> intIteratorPaxKey = intSetPaxKey.iterator();
while (intIteratorPaxKey.hasNext()) {
Integer intPaxId = intIteratorPaxKey.next();
PassengerArray passengerArrayObj = mapPaxSeat.get(intPaxId);
if (passengerArrayObj.getPaxId() == passengerArrayList.get(position).getPaxId() && passengerArrayObj.getSeatSelectedNumber() != null) {
holder.txt_seat_number.setText(passengerArrayObj.getSeatSelectedNumber());
holder.txt_seat_number.setVisibility(View.VISIBLE);
break;
} else {
holder.txt_seat_number.setVisibility(View.GONE);
}
}
}
holder.txt_passeger.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
View view = (View) v.getParent(); // Linear layout
LinearLayout txtPaxParentLayout = (LinearLayout) view.getParent(); //Linear lay row
try {
// unselect if any previous view is selected already
RecyclerView recycler = (RecyclerView) txtPaxParentLayout.getParent();
for (int i = 0; i < recycler.getChildCount(); i++) {
ViewHolder viewHolder = (ViewHolder) recycler.findViewHolderForAdapterPosition(i);
if (viewHolder.txt_passeger.getTag().toString().equals("Selected")) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
viewHolder.lyt_background.setBackground(context.getResources().getDrawable(R.color.color_white));
}
viewHolder.txt_passeger.setTag("Unselected");
Utils.DEBUG(TAG, "Recycler block Selection status: " + viewHolder.txt_passeger.getText() + ":" + viewHolder.txt_passeger.getTag());
viewHolder.txt_passeger.setTextColor(Color.BLACK);
}
}
} catch (Exception e) {
}
/**below code is to set only first passenger item selected*/
OTTextView txtv = v.findViewById(R.id.txt_passeger);
LinearLayout lyt_background = (LinearLayout) v.getParent();
if (txtv.getTag().toString().equals("Unselected")) {
// if passenger is selected
txtv.setTag("Selected");
txtv.setTextColor(Color.WHITE);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
lyt_background.setBackground(context.getResources().getDrawable(R.color.color_blue));
}
passengerArrayList.get(position).setAllowedToSelectSeat(true); //updating passengerArrayList by updating passenger status to select seat when the name is clicked
Utils.DEBUG(TAG, "Selection status: " + txtv.getText().toString() + ":" + txtv.getTag());
Utils.DEBUG(TAG, "Position: " + position + "; Current Passenger Object: " + new Gson().toJson(passengerArrayList.get(position)));
} else {
// if passenger unselected
txtv.setTag("Unselected"); //why make it unselected if already selected
txtv.setTextColor(Color.BLACK);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
lyt_background.setBackground(context.getResources().getDrawable(R.color.color_white));
}
passengerArrayList.get(position).setAllowedToSelectSeat(false); //why make it false if user clicks it to again select seat
Utils.DEBUG(TAG, "Selection status: " + txtv.getText().toString() + ":" + txtv.getTag());
Utils.DEBUG(TAG, "Position: " + position + "; Current Passenger Object: " + new Gson().toJson(passengerArrayList.get(position)));
}
l.onClickRecyclerItem(v, passengerArrayList.get(position));
}
});
}
My item xml code is as follows:
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<LinearLayout
android:id="#+id/lyt_background"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<com.optiontown.app.view.customview.OTTextView
android:id="#+id/txt_passeger"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="5"
android:paddingLeft="#dimen/dp_10"
android:paddingRight="#dimen/dp_10"
android:paddingTop="#dimen/dp_5"
android:paddingBottom="#dimen/dp_5"
android:textSize="#dimen/size_font_11"
android:textColor="#color/caldroid_black"
android:text="BLR>GOI" />
<ImageView
android:id="#+id/img_tick_mark"
android:layout_width="0dp"
android:layout_height="25dp"
android:layout_weight="1"
android:layout_gravity="right"
android:src="#drawable/tick_green_icon"/>
<com.optiontown.app.view.customview.OTTextView
android:id="#+id/txt_seat_number"
android:layout_width="0dp"
android:layout_height="#dimen/dp_27"
android:layout_weight="1"
android:text="07A"
android:gravity="center"
android:textColor="#color/color_font_green"
android:textStyle="bold"/>
</LinearLayout>
</LinearLayout>
Thanks in advance.
i want to animate textview in such a way that collide with display horizontally and vertically mean while that change random color of text and that runs infinte.is there any way??
i tried like
Animation a = AnimationUtils.loadAnimation(this, R.anim.anim);
a.setFillAfter(true);
a.reset();
tv.startAnimation(a);
i got solution....
MY Solution
textview.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:id="#+id/layout">
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Helo suni" />
</LinearLayout>
just call repeat function in on create ..
private void repeat() {
// TODO Auto-generated method stub
if (curAnimation == 1) {
animation1 = new TranslateAnimation(width / 2, width, 0, height / 2);
animation1.setDuration(800);
} else if (curAnimation == 2) {
animation1 = new TranslateAnimation(width, width / 2, height / 2, height);
animation1.setDuration(800);
}
else if (curAnimation == 3) {
animation1 = new TranslateAnimation(width / 2, 0, height, height / 2);
animation1.setDuration(800);
}
else if (curAnimation == 4) {
animation1 = new TranslateAnimation(0,width/2,height/2,0);
animation1.setDuration(800);
}
animation1.setFillAfter(true);
Random rnd = new Random();
int color = Color.argb(255, rnd.nextInt(256), rnd.nextInt(256),
rnd.nextInt(256));
tv.setTextColor(color);
tv.startAnimation(animation1);
animation1.setAnimationListener(new AnimationListener() {
#Override
public void onAnimationStart(Animation animation) {
// TODO Auto-generated method stub
}
#Override
public void onAnimationRepeat(Animation animation) {
// TODO Auto-generated method stub
}
#Override
public void onAnimationEnd(Animation animation) {
// TODO Auto-generated method stub
if (curAnimation == 4)
curAnimation = 1;
else
curAnimation++;
repeat();
}
});
}
Im trying to get my TextField to move on the screen. I want to be able to drag it to a new position on the screen. I´ve been struggling with this for days now and I really cant figure this one out...
This is what I´ve done so far:
InputProcessor drag = new InputAdapter() {
#Override
public boolean touchDown(int screenX, int screenY, int pointer,
int button) {
// TODO Auto-generated method stub
return super.touchDown(screenX, screenY, pointer, button);
}
#Override
public boolean touchUp(int screenX, int screenY, int pointer,
int button) {
int x = Gdx.input.getX();
int y = Gdx.input.getY();
textField.setPosition(x, y);
return true;
}
#Override
public boolean touchDragged(int screenX, int screenY, int pointer) {
// TODO Auto-generated method stub
return super.touchDragged(screenX, screenY, pointer);
}
};
game.inputMultiplexer = new InputMultiplexer();
game.inputMultiplexer.addProcessor(stage);
game.inputMultiplexer.addProcessor(stagePurc);
game.inputMultiplexer.addProcessor(stageText);
game.inputMultiplexer.addProcessor(drag);
Gdx.input.setInputProcessor(game.inputMultiplexer);
Here´s the textfield:
final TextField textField = new TextField(prefs.getString("textField", "Enter name:"), textstyle);
textField.setX(textX);
textField.setY(textY);
textField.setMaxLength(20);
textField.setWidth(textWidth);
textField.setHeight(textHeight);
Put the TextView in a LinearLayout:
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="top|center_horizontal"
android:clipChildren="false"
android:gravity="center_horizontal|center_vertical"
android:orientation="vertical" >
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:textColor="#color/text_color"
android:textSize="16sp" />
</LinearLayout>
Then set a touch listener:
txt.setOnTouchListener(new View.OnTouchListener() {
int initialX = 0;
int initialY = 0;
#Override
public boolean onTouch(View v, MotionEvent event) {
switch (event.getActionMasked()) {
case MotionEvent.ACTION_DOWN:
initialX = (int) event.getX();
initialY = (int) event.getY();
break;
case MotionEvent.ACTION_MOVE:
int currentX = (int) event.getX();
int currentY = (int) event.getY();
LinearLayout.LayoutParams lp = (LinearLayout.LayoutParams) txt.getLayoutParams();
int left = lp.leftMargin + (currentX - initialX);
int top = lp.topMargin + (currentY - initialY);
int right = lp.rightMargin - (currentX - initialX);
int bottom = lp.bottomMargin - (currentY - initialY);
lp.rightMargin = right;
lp.leftMargin = left;
lp.bottomMargin = bottom;
lp.topMargin = top;
txt.setLayoutParams(lp);
break;
default:
break;
}
return true;
}
});
Works pretty well. I got this code from here: How to make the TextView drag in LinearLayout smooth, in android?