错误:(74,34)错误:找不到符号方法getActivity()

时间:2015-12-01 09:00:02

标签: android

我收到此错误,我无法解决ot。请help.Error:(74,34)错误:找不到符号方法getActivity() 错误:(74,34)错误:找不到符号方法getActivity() 注意:某些输入文件使用或覆盖已弃用的API。 注意:使用-Xlint重新编译:弃用以获取详细信息。 注意:D:\ TENACLE WORK SPACE \ MCSK使用选项卡10 \ MCSK使用选项卡9 \ MCSK使用选项卡1 \ MCSK \ MCSK \ MCSK \ app \ src \ main \ java \ com \ qubit \ collection \ io \ CustomHTTP.java使用未经检查或不安全的操作。 注意:使用-Xlint重新编译:取消选中以获取详细信息。 错误:任务':app:compileDebugJavaWithJavac'执行失败。

import android.app.Activity;
import android.graphics.Color;
import android.graphics.Typeface;
import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TableLayout;
import android.widget.TableRow;
import android.widget.TextView;

import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.hannesdorfmann.adapterdelegates.AbsAdapterDelegate;
import com.qubit.collection.entities.InvoicedTransactions;
import com.qubit.mcsk.Const;
import com.qubit.mcsk.R;
import com.qubit.proceedings.model.DisplayableItem;
import com.qubit.proceedings.model.Payments;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.List;

/**
 * @author Hannes Dorfmann
 */
public class PaymentsAdapterDelegate extends AbsAdapterDelegate<List<DisplayableItem>> {

  private LayoutInflater inflater;

  public PaymentsAdapterDelegate(Activity activity, int viewType) {
    super(viewType);
    inflater = activity.getLayoutInflater();
  }

  @Override public boolean isForViewType(@NonNull List<DisplayableItem> items, int position) {
    return items.get(position) instanceof Payments;
  }

  @NonNull @Override public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent) {
    return new PaymentsViewHolder(inflater.inflate(R.layout.item_payments, parent, false));
  }

  @Override public void onBindViewHolder(@NonNull List<DisplayableItem> items, int position,
      @NonNull RecyclerView.ViewHolder holder) {

    PaymentsViewHolder vh = (PaymentsViewHolder) holder;

    for (Object o : Const.getInstance().getInvoicedTransactions()) {
      InvoicedTransactions i = vh.gson.fromJson(vh.gson.toJson(o), InvoicedTransactions.class);
      vh.invoicedTransactionsList.add(i);

      TableRow tr = new TableRow(getContext());
      TableRow.LayoutParams trlp = new TableRow.LayoutParams(TableRow.LayoutParams.MATCH_PARENT, TableRow.LayoutParams.WRAP_CONTENT);
      tr.setLayoutParams(trlp);

      //invoice no.
      TextView invoice_no = new TextView(getActivity());
      invoice_no.setLayoutParams(trlp);
      invoice_no.setText(i.getInvoice().getInvoiceNumber());
      invoice_no.setTextSize(10);

      //receipt
      TextView receipt = new TextView(getActivity());
      receipt.setLayoutParams(trlp);
      receipt.setText(i.getReceiptNo());
      receipt.setTextColor(Color.DKGRAY);
      receipt.setTextSize(10);

      //amount
      TextView amount = new TextView(getActivity());
      amount.setLayoutParams(trlp);
      amount.setText("" + i.getAmount());
      amount.setTextSize(10);
      amount.setTypeface(null, Typeface.BOLD);
      amount.setTextColor(Color.BLUE);
      amount.setGravity(Gravity.CENTER_VERTICAL | Gravity.CENTER_HORIZONTAL);


      SimpleDateFormat simpleDateFormat = new SimpleDateFormat();
      simpleDateFormat.applyPattern("dd-MM-yyyy HH:mm:ss");

      TextView date = new TextView(getActivity());
      date.setLayoutParams(trlp);
      date.setText(simpleDateFormat.format(i.getTime()));
      date.setTextColor(Color.DKGRAY);
      date.setTextSize(10);

      tr.addView(invoice_no);
      tr.addView(receipt);
      tr.addView(amount);
      tr.addView(date);

      vh.payments_table.addView(tr, vh.tllp);
    }



  }

  static class PaymentsViewHolder extends RecyclerView.ViewHolder {


    static Gson gson = new GsonBuilder()
            .setDateFormat("yyyyMMddHHmmss")
            .create();
    static Gson gsonPretty = new GsonBuilder()
            .setPrettyPrinting()
            .setDateFormat("yyyyMMddHHmmss")
            .create();
    TextView mobile_no, email_add, physical_address, town, geo, acc_name, customer_name, statuss, cust_id, expiry, invoiceamnt, invoicebalance, invoicedatecreated, invoicestatus;
    List<InvoicedTransactions> invoicedTransactionsList = new ArrayList<InvoicedTransactions>();
    TableLayout payments_table = (TableLayout) itemView.findViewById(R.id.payments_table);
    TableLayout.LayoutParams tllp = new TableLayout.LayoutParams(TableLayout.LayoutParams.MATCH_PARENT, TableLayout.LayoutParams.WRAP_CONTENT);

    public PaymentsViewHolder(View itemView) {
      super(itemView);

      payments_table.setLayoutParams(tllp);
      invoicedTransactionsList.clear();
    }
  }
}

1 个答案:

答案 0 :(得分:0)

使用getActivity()代替TextView receipt = new TextView(activity);

fragment

PaymentsAdapterDelegate 不是try: with open(path_to_file, 'r') as f: # read score from file score = ... except FileNotFoundError: with open(path_to_file, 'w') as f: # save initial data to file score = initial_data